Fix 10.7 compatibility and add a window to show an exception log

This commit is contained in:
galad87 committed 2015-08-29 11:41:24 +02:00
1 parent 60b1c60155
commit d1360727ec
13 files changed
+452

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
/* HBApplication.m $
This file is part of the HandBrake source code.
Homepage: <http://handbrake.fr/>.
It may be used under the terms of the GNU General Public License. */
#import "SBApplication.h"
#import "SBExceptionAlertController.h"
@implementation SBApplication
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];
SBExceptionAlertController *alertController = [[SBExceptionAlertController alloc] init];
alertController.exceptionMessage = exceptionMessage;
alertController.exceptionBacktrace = [self _formattedExceptionBacktrace:exception.callStackSymbols];
NSInteger result = [alertController runModal];
if (result == SBExceptionAlertControllerResultCrash)
{
CrashMyApplication();
}
}
}
@catch (NSException *e)
{
// Suppress any exceptions raised in the handling
}
}
@end