From 467cc4ed93771aae1d6dca546758dffe5312899b Mon Sep 17 00:00:00 2001 From: ritsuka Date: Tue, 24 Mar 2015 07:32:31 +0000 Subject: [PATCH] MacGui: add an alert window to show the exceptions not handled. Hopefully it will make it easier for users to report this kind of issue. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7010 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/English.lproj/ExceptionAlert.xib | 126 +++++++++++++++++++++ macosx/HBApplication.h | 11 ++ macosx/HBApplication.m | 63 +++++++++++ macosx/HBExceptionAlertController.h | 25 ++++ macosx/HBExceptionAlertController.m | 33 ++++++ macosx/HandBrake.xcodeproj/project.pbxproj | 24 ++++ macosx/Info.plist.m4 | 2 +- 7 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 macosx/English.lproj/ExceptionAlert.xib create mode 100644 macosx/HBApplication.h create mode 100644 macosx/HBApplication.m create mode 100644 macosx/HBExceptionAlertController.h create mode 100644 macosx/HBExceptionAlertController.m diff --git a/macosx/English.lproj/ExceptionAlert.xib b/macosx/English.lproj/ExceptionAlert.xib new file mode 100644 index 000000000..2b0c747a3 --- /dev/null +++ b/macosx/English.lproj/ExceptionAlert.xib @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macosx/HBApplication.h b/macosx/HBApplication.h new file mode 100644 index 000000000..2fbeab833 --- /dev/null +++ b/macosx/HBApplication.h @@ -0,0 +1,11 @@ +/* HBApplication.h $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import + +@interface HBApplication : NSApplication + +@end diff --git a/macosx/HBApplication.m b/macosx/HBApplication.m new file mode 100644 index 000000000..d725b1bad --- /dev/null +++ b/macosx/HBApplication.m @@ -0,0 +1,63 @@ +/* HBApplication.m $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import "HBApplication.h" +#import "HBExceptionAlertController.h" +#import "HBUtilities.h" + +@implementation HBApplication + +static void CrashMyApplication() +{ + *(char *)0x08 = 1; +} + +- (NSAttributedString *)_formattedExceptionBacktrace:(NSArray *)backtrace +{ + NSMutableAttributedString *result = [[NSMutableAttributedString alloc] init]; + for (__strong NSString *s in backtrace) + { + s = [s stringByAppendingString:@"\n"]; + NSAttributedString *attrS = [[NSAttributedString alloc] initWithString:s]; + [result appendAttributedString:attrS]; + } + [result addAttribute:NSFontAttributeName value:[NSFont fontWithName:@"Monaco" size:10] range:NSMakeRange(0, result.length)]; + return result; +} + +- (void)reportException:(NSException *)exception +{ + // NSApplication simply logs the exception to the console. We want to let the user know + // when it happens in order to possibly prevent subsequent random crashes that are difficult to debug + @try + { + @autoreleasepool + { + // Create a string based on the exception + NSString *exceptionMessage = [NSString stringWithFormat:@"%@\nReason: %@\nUser Info: %@", exception.name, exception.reason, exception.userInfo]; + // Always log to console for history + + [HBUtilities writeToActivityLog:"Exception raised:\n%s", exceptionMessage.UTF8String]; + [HBUtilities writeToActivityLog:"Backtrace:\n%s", exception.callStackSymbols.description.UTF8String]; + + HBExceptionAlertController *alertController = [[HBExceptionAlertController alloc] init]; + alertController.exceptionMessage = exceptionMessage; + alertController.exceptionBacktrace = [self _formattedExceptionBacktrace:exception.callStackSymbols]; + + NSInteger result = [alertController runModal]; + if (result == HBExceptionAlertControllerResultCrash) + { + CrashMyApplication(); + } + } + } + @catch (NSException *e) + { + // Suppress any exceptions raised in the handling + } +} + +@end diff --git a/macosx/HBExceptionAlertController.h b/macosx/HBExceptionAlertController.h new file mode 100644 index 000000000..aaf49647c --- /dev/null +++ b/macosx/HBExceptionAlertController.h @@ -0,0 +1,25 @@ +/* HBExceptionAlertController.h $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import + +typedef NS_ENUM(NSUInteger, HBExceptionAlertControllerResult) { + HBExceptionAlertControllerResultCrash, + HBExceptionAlertControllerResultContinue, +}; + +@interface HBExceptionAlertController : NSWindowController + +// Properties are used by bindings +@property (copy) NSString *exceptionMessage; +@property (copy) NSAttributedString *exceptionBacktrace; + +- (IBAction)btnCrashClicked:(id)sender; +- (IBAction)btnContinueClicked:(id)sender; + +- (NSInteger)runModal; + +@end diff --git a/macosx/HBExceptionAlertController.m b/macosx/HBExceptionAlertController.m new file mode 100644 index 000000000..001794cac --- /dev/null +++ b/macosx/HBExceptionAlertController.m @@ -0,0 +1,33 @@ +/* HBExceptionAlertController.m $ + + This file is part of the HandBrake source code. + Homepage: . + It may be used under the terms of the GNU General Public License. */ + +#import "HBExceptionAlertController.h" + +@implementation HBExceptionAlertController + +- (id)init +{ + return [self initWithWindowNibName:@"ExceptionAlert"]; +} + +- (NSInteger)runModal +{ + return [NSApp runModalForWindow:self.window]; +} + +- (IBAction)btnCrashClicked:(id)sender +{ + [self.window orderOut:nil]; + [NSApp stopModalWithCode:HBExceptionAlertControllerResultCrash]; +} + +- (IBAction)btnContinueClicked:(id)sender +{ + [self.window orderOut:nil]; + [NSApp stopModalWithCode:HBExceptionAlertControllerResultContinue]; +} + +@end diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index d4581b9b5..a9a07e89a 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -150,6 +150,9 @@ A955128B1A320B02001BFC6F /* libjansson.a in Frameworks */ = {isa = PBXBuildFile; fileRef = A95512881A320A12001BFC6F /* libjansson.a */; }; A9597A2A1A49749D00007771 /* HBRange+UIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A9597A291A49749D00007771 /* HBRange+UIAdditions.m */; }; A967E4BA1A16768200DF1DFC /* EncodeCanceled@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = A967E4B91A16768200DF1DFC /* EncodeCanceled@2x.png */; }; + A9706CB41AC1436F00BAEAA8 /* HBApplication.m in Sources */ = {isa = PBXBuildFile; fileRef = A9706CB31AC1436F00BAEAA8 /* HBApplication.m */; }; + A9706CB71AC1437800BAEAA8 /* HBExceptionAlertController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9706CB61AC1437800BAEAA8 /* HBExceptionAlertController.m */; }; + A9706CBA1AC1452800BAEAA8 /* ExceptionAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9706CB81AC1452800BAEAA8 /* ExceptionAlert.xib */; }; A971281F1A2C75180088C076 /* HBTitle.m in Sources */ = {isa = PBXBuildFile; fileRef = A971281E1A2C75180088C076 /* HBTitle.m */; }; A983494F1A9A64B80059CB94 /* presets.plist in Resources */ = {isa = PBXBuildFile; fileRef = A983494E1A9A64B80059CB94 /* presets.plist */; }; A98C29C41977B10600AF5DED /* HBLanguagesSelection.m in Sources */ = {isa = PBXBuildFile; fileRef = A98C29C31977B10600AF5DED /* HBLanguagesSelection.m */; }; @@ -417,6 +420,11 @@ A9597A281A49749D00007771 /* HBRange+UIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "HBRange+UIAdditions.h"; sourceTree = ""; }; A9597A291A49749D00007771 /* HBRange+UIAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "HBRange+UIAdditions.m"; sourceTree = ""; }; A967E4B91A16768200DF1DFC /* EncodeCanceled@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "EncodeCanceled@2x.png"; sourceTree = ""; }; + A9706CB21AC1436F00BAEAA8 /* HBApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBApplication.h; sourceTree = ""; }; + A9706CB31AC1436F00BAEAA8 /* HBApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBApplication.m; sourceTree = ""; }; + A9706CB51AC1437800BAEAA8 /* HBExceptionAlertController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBExceptionAlertController.h; sourceTree = ""; }; + A9706CB61AC1437800BAEAA8 /* HBExceptionAlertController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBExceptionAlertController.m; sourceTree = ""; }; + A9706CB91AC1452800BAEAA8 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = ExceptionAlert.xib; sourceTree = ""; }; A971281D1A2C75180088C076 /* HBTitle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBTitle.h; sourceTree = ""; }; A971281E1A2C75180088C076 /* HBTitle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBTitle.m; sourceTree = ""; }; A983494E1A9A64B80059CB94 /* presets.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = presets.plist; sourceTree = ""; }; @@ -700,6 +708,10 @@ A952392E199A647F00588AEF /* Presets */, A9AA44781970664A00D7DEFC /* HBUtilities.h */, A9AA44791970664A00D7DEFC /* HBUtilities.m */, + A9706CB21AC1436F00BAEAA8 /* HBApplication.h */, + A9706CB31AC1436F00BAEAA8 /* HBApplication.m */, + A9706CB51AC1437800BAEAA8 /* HBExceptionAlertController.h */, + A9706CB61AC1437800BAEAA8 /* HBExceptionAlertController.m */, A98F00771A972007001C2298 /* Output Redirect */, A9E66D6E1A67A2A8007B641D /* HBDistributedArray.h */, A9E66D6F1A67A2A8007B641D /* HBDistributedArray.m */, @@ -823,6 +835,7 @@ 273F218414ADDDA10021BE6D /* PictureSettings.xib */, 273F218614ADDDA10021BE6D /* Preferences.xib */, 273F218814ADDDA10021BE6D /* Queue.xib */, + A9706CB81AC1452800BAEAA8 /* ExceptionAlert.xib */, ); path = English.lproj; sourceTree = ""; @@ -1231,6 +1244,7 @@ D2BCB11A16F5152C0084604C /* preview@2x.png in Resources */, D2BCB11B16F5152C0084604C /* settings@2x.png in Resources */, D2BCB12316F5154E0084604C /* settings.png in Resources */, + A9706CBA1AC1452800BAEAA8 /* ExceptionAlert.xib in Resources */, D2BCB12416F5154E0084604C /* showqueue.png in Resources */, D2BCB12516F5154E0084604C /* showqueue@2x.png in Resources */, D2BCB12616F5154E0084604C /* source.png in Resources */, @@ -1263,6 +1277,7 @@ A98C29C41977B10600AF5DED /* HBLanguagesSelection.m in Sources */, A9BB0F2719A0ECE40079F1C1 /* HBHUDButtonCell.m in Sources */, A932E273198834130047D13E /* HBAudioDefaults.m in Sources */, + A9706CB71AC1437800BAEAA8 /* HBExceptionAlertController.m in Sources */, A92268781A6E555500A8D5C5 /* HBAppDelegate.m in Sources */, A91806711A4807B000FC9BED /* HBRange.m in Sources */, A9DEC8771A23C88D00C79B48 /* HBVideo.m in Sources */, @@ -1299,6 +1314,7 @@ A90A0CAF1988D57200DA65CE /* HBAudioTrackPreset.m in Sources */, A91017B41A64440A00039BFB /* HBSubtitles.m in Sources */, 273F20BA14ADBE670021BE6D /* HBPictureController.m in Sources */, + A9706CB41AC1436F00BAEAA8 /* HBApplication.m in Sources */, A9CF25F71990D6820023F727 /* HBPresetsViewController.m in Sources */, A9537BF91A48AC9000141102 /* HBFilters+UIAdditions.m in Sources */, 273F20BE14ADC09F0021BE6D /* main.mm in Sources */, @@ -1421,6 +1437,14 @@ name = Video.xib; sourceTree = ""; }; + A9706CB81AC1452800BAEAA8 /* ExceptionAlert.xib */ = { + isa = PBXVariantGroup; + children = ( + A9706CB91AC1452800BAEAA8 /* English */, + ); + name = ExceptionAlert.xib; + sourceTree = ""; + }; A9935211196F38A70069C6B7 /* ChaptersTitles.xib */ = { isa = PBXVariantGroup; children = ( diff --git a/macosx/Info.plist.m4 b/macosx/Info.plist.m4 index 9c490e6a6..a75471578 100644 --- a/macosx/Info.plist.m4 +++ b/macosx/Info.plist.m4 @@ -63,7 +63,7 @@ All rights reserved. NSMainNibFile MainMenu NSPrincipalClass - NSApplication + HBApplication SUFeedURL __HB_url_appcast -- 2.40.0