[vlc-commits] macosx: do not draw gradients into empty paths

Marvin Scholz git at videolan.org
Mon May 4 18:46:14 CEST 2020


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Mon May  4 18:42:38 2020 +0200| [392c5f71c733ea2715a2e7d471cb9d1f8f5fe055] | committer: Marvin Scholz

macosx: do not draw gradients into empty paths

Drawing an NSGradient into an empty bezier path causes an exception,
crashing the application.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=392c5f71c733ea2715a2e7d471cb9d1f8f5fe055
---

 modules/gui/macosx/views/VLCBottomBarView.m    | 18 ++++++++++++------
 modules/gui/macosx/views/VLCSliderCell.m       |  5 ++++-
 modules/gui/macosx/views/VLCVolumeSliderCell.m | 14 ++++++++++----
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/modules/gui/macosx/views/VLCBottomBarView.m b/modules/gui/macosx/views/VLCBottomBarView.m
index 6cedad9280..47e44444b0 100644
--- a/modules/gui/macosx/views/VLCBottomBarView.m
+++ b/modules/gui/macosx/views/VLCBottomBarView.m
@@ -120,15 +120,21 @@
 
     NSRect barRect = self.bounds;
 
+    if (NSIsEmptyRect(barRect))
+        return;
+
     [[NSColor clearColor] setFill];
     NSRectFill(barRect);
 
-    if (_isDark) {
-        [_darkGradient drawInBezierPath:_rectanglePath angle:270.0];
-        [_darkStroke setStroke];
-    } else {
-        [_lightGradient drawInBezierPath:_rectanglePath angle:270.0];
-        [_lightStroke setStroke];
+    // Drawing a gradient into an empty bezier path will cause an exception, prevent that
+    if (![_rectanglePath isEmpty]) {
+        if (_isDark) {
+            [_darkGradient drawInBezierPath:_rectanglePath angle:270.0];
+            [_darkStroke setStroke];
+        } else {
+            [_lightGradient drawInBezierPath:_rectanglePath angle:270.0];
+            [_lightStroke setStroke];
+        }
     }
 
     [_separatorPath stroke];
diff --git a/modules/gui/macosx/views/VLCSliderCell.m b/modules/gui/macosx/views/VLCSliderCell.m
index 3c27b28c33..50160f86e0 100644
--- a/modules/gui/macosx/views/VLCSliderCell.m
+++ b/modules/gui/macosx/views/VLCSliderCell.m
@@ -223,7 +223,10 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt
 
     // Empty Track Drawing
     NSBezierPath* emptyTrackPath = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:3 yRadius:3];
-    [_trackGradient drawInBezierPath:emptyTrackPath angle:-90];
+
+    // Drawing a gradient into an empty bezier path will cause an exception, prevent that
+    if (![emptyTrackPath isEmpty])
+        [_trackGradient drawInBezierPath:emptyTrackPath angle:-90];
 
     if (_isKnobHidden) {
         [_trackStrokeColor setStroke];
diff --git a/modules/gui/macosx/views/VLCVolumeSliderCell.m b/modules/gui/macosx/views/VLCVolumeSliderCell.m
index 115987bcff..e42dd17fd8 100644
--- a/modules/gui/macosx/views/VLCVolumeSliderCell.m
+++ b/modules/gui/macosx/views/VLCVolumeSliderCell.m
@@ -142,13 +142,15 @@
     // Draw knob
     NSBezierPath* knobPath = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(knobRect, 1.0, 1.0)];
     if (self.isHighlighted) {
-        if (_knobGradient) {
+        // Drawing a gradient into an empty bezier path will cause an exception, prevent that
+        if (_knobGradient && ![knobPath isEmpty]) {
             [_knobGradient drawInBezierPath:knobPath angle:_knobGradientAngleHighlighted];
         } else {
             [_activeKnobFillColor setFill];
         }
     } else {
-        if (_knobGradient) {
+        // Drawing a gradient into an empty bezier path will cause an exception, prevent that
+        if (_knobGradient && ![knobPath isEmpty]) {
             [_knobGradient drawInBezierPath:knobPath angle:_knobGradientAngle];
         } else {
             [_knobFillColor setFill];
@@ -198,10 +200,14 @@
         [emptyTrackPath fill];
 
         // Filled part drawing
-        [_trackGradient drawInBezierPath:leadingTrackPath angle:-90];
+        // Drawing a gradient into an empty bezier path will cause an exception, prevent that
+        if (![leadingTrackPath isEmpty])
+            [_trackGradient drawInBezierPath:leadingTrackPath angle:-90];
     } else {
         // Empty part drawing
-        [_trackGradient drawInBezierPath:emptyTrackPath angle:-90];
+        // Drawing a gradient into an empty bezier path will cause an exception, prevent that
+        if (![emptyTrackPath isEmpty])
+            [_trackGradient drawInBezierPath:emptyTrackPath angle:-90];
 
         // Filled part drawing
         [_filledTrackColor setFill];



More information about the vlc-commits mailing list