vlc | branch: master | Marvin Scholz <[email protected]> | Wed Jun 3 15:45:22 2020 +0200| [2a5d25e03a051287248afb47e540e43b9a6afd6e] | 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. > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=2a5d25e03a051287248afb47e540e43b9a6afd6e --- modules/gui/macosx/Makefile.am | 2 ++ .../macosx/extensions/NSGradient+VLCAdditions.h | 33 ++++++++++++++++++++ .../macosx/extensions/NSGradient+VLCAdditions.m | 35 ++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am index eeb17c10d9..596eda4662 100644 --- a/modules/gui/macosx/Makefile.am +++ b/modules/gui/macosx/Makefile.am @@ -30,6 +30,8 @@ libmacosx_plugin_la_SOURCES = \ gui/macosx/coreinteraction/VLCHotkeysController.m \ gui/macosx/coreinteraction/VLCVideoFilterHelper.h \ gui/macosx/coreinteraction/VLCVideoFilterHelper.m \ + gui/macosx/extensions/NSGradient+VLCAdditions.h \ + gui/macosx/extensions/NSGradient+VLCAdditions.m \ gui/macosx/extensions/NSColor+VLCAdditions.h \ gui/macosx/extensions/NSColor+VLCAdditions.m \ gui/macosx/extensions/NSFont+VLCAdditions.h \ diff --git a/modules/gui/macosx/extensions/NSGradient+VLCAdditions.h b/modules/gui/macosx/extensions/NSGradient+VLCAdditions.h new file mode 100644 index 0000000000..1a1a9d14d5 --- /dev/null +++ b/modules/gui/macosx/extensions/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> + +@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; + +@end diff --git a/modules/gui/macosx/extensions/NSGradient+VLCAdditions.m b/modules/gui/macosx/extensions/NSGradient+VLCAdditions.m new file mode 100644 index 0000000000..4f06e88ca6 --- /dev/null +++ b/modules/gui/macosx/extensions/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" + +@implementation NSGradient (VLCAdditions) + +- (void)vlc_safeDrawInBezierPath:(NSBezierPath *)path + angle:(CGFloat)angle +{ + if ([path isEmpty]) + return; + [self drawInBezierPath:path angle:angle]; +} + +@end _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
