[vlc-commits] macosx: add category for safe NSGradient drawing

Marvin Scholz git at videolan.org
Wed Jun 3 16:51:19 CEST 2020


vlc/vlc-3.0 | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Jun  3 15:45:22 2020 +0200| [0ce240a45e505f7263738e8746d92ad847bd1df8] | committer: Marvin Scholz

macosx: add category for safe NSGradient drawing

Trying to draw a NSGradient into an empty NSBezierPath throws
and exception, crashing the application.

To prevent that we have workarounds at every place where we called
drawInBezierPath:angle:, instead just use a category which makes
the code cleaner and keeps the logic for the workaround in one place.

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

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

 modules/gui/macosx/Makefile.am               |  1 +
 modules/gui/macosx/NSGradient+VLCAdditions.h | 33 ++++++++++++++++++++++++++
 modules/gui/macosx/NSGradient+VLCAdditions.m | 35 ++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+)

diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index 3b7fd43286..050ee0a456 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -38,6 +38,7 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/VLCMainMenu.h gui/macosx/VLCMainMenu.m \
 	gui/macosx/VLCMainWindowTitleView.h gui/macosx/VLCMainWindowTitleView.m \
 	gui/macosx/misc.h gui/macosx/misc.m \
+	gui/macosx/NSGradient+VLCAdditions.h gui/macosx/NSGradient+VLCAdditions.m \
 	gui/macosx/NSSound+VLCAdditions.h gui/macosx/NSSound+VLCAdditions.m \
 	gui/macosx/NSScreen+VLCAdditions.h gui/macosx/NSScreen+VLCAdditions.m \
 	gui/macosx/VLCOpenWindowController.h gui/macosx/VLCOpenWindowController.m \
diff --git a/modules/gui/macosx/NSGradient+VLCAdditions.h b/modules/gui/macosx/NSGradient+VLCAdditions.h
new file mode 100644
index 0000000000..1a1a9d14d5
--- /dev/null
+++ b/modules/gui/macosx/NSGradient+VLCAdditions.h
@@ -0,0 +1,33 @@
+/*****************************************************************************
+ * NSGradient+VLCAdditions.h: Category that adds safer bezier path operations
+ *****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+ at interface NSGradient (VLCAdditions)
+
+/* Safe alternative to drawInBezierPath:angle: which will throw an
+ * exception when trying to draw into an empty NSBezierPath.
+ */
+- (void)vlc_safeDrawInBezierPath:(NSBezierPath *)path 
+                           angle:(CGFloat)angle;
+
+ at end
diff --git a/modules/gui/macosx/NSGradient+VLCAdditions.m b/modules/gui/macosx/NSGradient+VLCAdditions.m
new file mode 100644
index 0000000000..4f06e88ca6
--- /dev/null
+++ b/modules/gui/macosx/NSGradient+VLCAdditions.m
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * NSGradient+VLCAdditions.m: Category that adds safer bezier path operations
+ *****************************************************************************
+ * Copyright (C) 2020 VLC authors and VideoLAN
+ *
+ * Authors: Marvin Scholz <epirat07 at gmail dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "NSGradient+VLCAdditions.h"
+
+ at implementation NSGradient (VLCAdditions)
+
+- (void)vlc_safeDrawInBezierPath:(NSBezierPath *)path 
+                           angle:(CGFloat)angle
+{
+    if ([path isEmpty])
+        return;
+    [self drawInBezierPath:path angle:angle];
+}
+
+ at end



More information about the vlc-commits mailing list