Commits

Jason Harris  committed 2a4c680

- Make sure all web view accesses and calls are done on the main thread since web views are
not thread safe. This should fix a lot of the crashes.

  • Participants
  • Parent commits bf46f5a

Comments (0)

Files changed (2)

File Classes/FilesView/FSViewer.m

 	if (parentConcertinaView && [parentConcertinaView isSubviewCollapsed:subView])
 		return;
 
-	WebScriptObject* script = [detailedPatchesWebView windowScriptObject];
-	[script setValue:self forKey:@"machgWebviewController"];
-	[script callWebScriptMethod:@"changeFontSizeOfDiff" withArguments:[NSArray arrayWithObject:fstr(@"%f",FontSizeOfDifferencesWebviewFromDefaults())]];
+	dispatch_async(mainQueue(), ^{
+		WebScriptObject* script = [detailedPatchesWebView windowScriptObject];
+		[script setValue:self forKey:@"machgWebviewController"];
+		[script callWebScriptMethod:@"changeFontSizeOfDiff" withArguments:[NSArray arrayWithObject:fstr(@"%f",FontSizeOfDifferencesWebviewFromDefaults())]];
+			
+		NSArray* selectedPaths = [self absolutePathsOfSelectedFilesInBrowser];
+		if (IsEmpty(selectedPaths))
+		{
+			[detailedPatchesWebView setBackingPatch:nil andFallbackMessage:@""];
+			return;
+		}
 		
-	NSArray* selectedPaths = [self absolutePathsOfSelectedFilesInBrowser];
-	if (IsEmpty(selectedPaths))
-	{
-		[detailedPatchesWebView setBackingPatch:nil andFallbackMessage:@""];
-		return;
-	}
-	
-	NSString* rootPath = [self absolutePathOfRepositoryRoot];
-	[detailedPatchesWebView regenerateDifferencesForSelectedPaths:selectedPaths andRoot:rootPath];
+		NSString* rootPath = [self absolutePathOfRepositoryRoot];
+		[detailedPatchesWebView regenerateDifferencesForSelectedPaths:selectedPaths andRoot:rootPath];
+	});
 }
 
 - (void) updateExclusionDataForChangedPaths:(NSArray*)absoluteChangedPaths andRoot:(NSString*)rootPath

File Classes/PatchesModel/PatchesWebview.m

 
 - (void) setBackingPatch:(PatchData*)patchData andFallbackMessage:(NSString*)fallbackMessage
 {
-	[[self windowScriptObject] setValue:self forKey:@"machgWebviewController"];
-	[self setBackingPatch:patchData andFallbackMessage:fallbackMessage withTaskNumber:[self nextTaskNumber]];
+	dispatch_async(mainQueue(), ^{
+		[[self windowScriptObject] setValue:self forKey:@"machgWebviewController"];
+		[self setBackingPatch:patchData andFallbackMessage:fallbackMessage withTaskNumber:[self nextTaskNumber]];
+	});
 }
 
 - (void) setBackingPatch:(PatchData*)patchData andFallbackMessage:(NSString*)fallbackMessage withTaskNumber:(NSInteger)taskNumber
 {
-	[[self windowScriptObject] setValue:self forKey:@"machgWebviewController"];
-	if ([self taskIsStale:taskNumber])
-		return;
-	fallbackMessage_ = fallbackMessage;
-	backingPatch_ = patchData;
-	repositoryRootForPatch_ = [[parentController myDocument] absolutePathOfRepositoryRoot];
-	[self redisplayViewForTaskNumber: taskNumber];
+	dispatch_async(mainQueue(), ^{
+		[[self windowScriptObject] setValue:self forKey:@"machgWebviewController"];
+		if ([self taskIsStale:taskNumber])
+			return;
+		fallbackMessage_ = fallbackMessage;
+		backingPatch_ = patchData;
+		repositoryRootForPatch_ = [[parentController myDocument] absolutePathOfRepositoryRoot];
+		[self redisplayViewForTaskNumber: taskNumber];
+	});
 }
 
 
 	if ([self taskIsStale:[theRegenerationTaskContoller taskNumber]])
 		return;
 	if ([[theRegenerationTaskContoller shellTask] isRunning])
-	{
-		WebScriptObject* script = [self windowScriptObject];
-		[script callWebScriptMethod:@"showGeneratingMessage" withArguments:[NSArray arrayWithObject:@"Generating Differences… "]];
-	}
+		dispatch_async(mainQueue(), ^{
+			WebScriptObject* script = [self windowScriptObject];
+			[script callWebScriptMethod:@"showGeneratingMessage" withArguments:[NSArray arrayWithObject:@"Generating Differences… "]];
+		});
 }
 
 
 
 - (void) hunkWasExcluded:(NSNotification*)notification
 {
-	NSString* hunkHash = [[notification userInfo] objectForKey:kHunkHash];
-	[[self windowScriptObject] callWebScriptMethod:@"excludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+	dispatch_async(mainQueue(), ^{
+		NSString* hunkHash = [[notification userInfo] objectForKey:kHunkHash];
+		[[self windowScriptObject] callWebScriptMethod:@"excludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+	});
 }
 
 - (void) hunkWasIncluded:(NSNotification*)notification
 {
-	NSString* hunkHash = [[notification userInfo] objectForKey:kHunkHash];
-	[[self windowScriptObject] callWebScriptMethod:@"inludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+	dispatch_async(mainQueue(), ^{
+		NSString* hunkHash = [[notification userInfo] objectForKey:kHunkHash];
+		[[self windowScriptObject] callWebScriptMethod:@"inludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+	});
 }
 
 - (void) fileWasExcluded:(NSNotification*)notification
 	if (!filePatch)
 		return;
 	
-	NSSet* hunkExclusionSet = [[parentController hunkExclusions] hunkExclusionSetForRoot:repositoryRootForPatch_ andFile:fileName];
-	for (NSString* hunkHash in hunkExclusionSet)
-		[[self windowScriptObject] callWebScriptMethod:@"excludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+	dispatch_async(mainQueue(), ^{
+		NSSet* hunkExclusionSet = [[parentController hunkExclusions] hunkExclusionSetForRoot:repositoryRootForPatch_ andFile:fileName];
+		for (NSString* hunkHash in hunkExclusionSet)
+			[[self windowScriptObject] callWebScriptMethod:@"excludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+	});
 }
 
 - (void) fileWasIncluded:(NSNotification*)notification
 	FilePatch* filePatch = [backingPatch_ filePatchForFilePath:fileName];
 	if (!filePatch)
 		return;
-	
-	NSSet* validHunkHashSet = [[parentController hunkExclusions] validHunkHashSetForRoot:repositoryRootForPatch_ andFile:fileName];
-	for (NSString* hunkHash in validHunkHashSet)
-		[[self windowScriptObject] callWebScriptMethod:@"includeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+
+	dispatch_async(mainQueue(), ^{
+		NSSet* validHunkHashSet = [[parentController hunkExclusions] validHunkHashSetForRoot:repositoryRootForPatch_ andFile:fileName];
+		for (NSString* hunkHash in validHunkHashSet)
+			[[self windowScriptObject] callWebScriptMethod:@"includeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+	});
 }
 
 
 {
 	if ([[parentController myDocument] inMergeState])
 		return;
-	WebScriptObject* script = [self windowScriptObject];
-	for (FilePatch* filePatch in [backingPatch_ filePatches])
-	{
-		NSString* path = [filePatch filePath];
-		NSSet* hunkExclusionSet = [[parentController hunkExclusions] hunkExclusionSetForRoot:repositoryRootForPatch_ andFile:path];
-		for (NSString* hunkHash in hunkExclusionSet)
-			[script callWebScriptMethod:@"excludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
-	}
+	dispatch_async(mainQueue(), ^{
+		WebScriptObject* script = [self windowScriptObject];
+		for (FilePatch* filePatch in [backingPatch_ filePatches])
+		{
+			NSString* path = [filePatch filePath];
+			NSSet* hunkExclusionSet = [[parentController hunkExclusions] hunkExclusionSetForRoot:repositoryRootForPatch_ andFile:path];
+			for (NSString* hunkHash in hunkExclusionSet)
+				[script callWebScriptMethod:@"excludeViewHunkStatus" withArguments:[NSArray arrayWithObject:hunkHash]];
+		}
+	});
 }
 
 - (void) doExternalDiffOfFile:(NSString*)fileName