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

Marvin Scholz git at videolan.org
Mon May 4 18:50:32 CEST 2020


vlc/vlc-3.0 | branch: master | Marvin Scholz <epirat07 at gmail.com> | Mon May  4 18:42:38 2020 +0200| [0daacd39b8e807a2c9256f7eb3244964bc179a3c] | 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.

(cherry picked from commit 392c5f71c733ea2715a2e7d471cb9d1f8f5fe055)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=0daacd39b8e807a2c9256f7eb3244964bc179a3c
---

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

diff --git a/modules/gui/macosx/VLCBottomBarView.m b/modules/gui/macosx/VLCBottomBarView.m
index d52ac90e7f..912c355532 100644
--- a/modules/gui/macosx/VLCBottomBarView.m
+++ b/modules/gui/macosx/VLCBottomBarView.m
@@ -123,15 +123,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/VLCSliderCell.m b/modules/gui/macosx/VLCSliderCell.m
index 7db11da666..09fc9e2e1a 100644
--- a/modules/gui/macosx/VLCSliderCell.m
+++ b/modules/gui/macosx/VLCSliderCell.m
@@ -227,7 +227,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/VLCVolumeSliderCell.m b/modules/gui/macosx/VLCVolumeSliderCell.m
index 3477126b5a..489ac6dd76 100644
--- a/modules/gui/macosx/VLCVolumeSliderCell.m
+++ b/modules/gui/macosx/VLCVolumeSliderCell.m
@@ -145,13 +145,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];
@@ -201,10 +203,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