]> git.sesse.net Git - vlc/commitdiff
macosx: Update progress dialog on the main thread, make check thread safe
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Sat, 21 Mar 2015 16:31:20 +0000 (17:31 +0100)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Sat, 21 Mar 2015 16:35:44 +0000 (17:35 +0100)
This should fix some crashes as reported by the users.

modules/gui/macosx/coredialogs.h
modules/gui/macosx/coredialogs.m
modules/gui/macosx/intf.m

index 239600b08c4047b59b59f35c751d517bab5ebdfe..2c9624713d0edfb27652b1328180a9b339214a74 100644 (file)
@@ -76,6 +76,8 @@
 }
 + (VLCCoreDialogProvider *)sharedInstance;
 
+@property (atomic,readwrite) BOOL progressCancelled;
+
 -(void)performEventWithObject: (NSValue *)o_value ofType: (const char*)type;
 
 -(void)showFatalDialog: (NSValue *)o_value;
@@ -88,7 +90,6 @@
 -(void)showProgressDialogOnMainThread: (NSValue *)o_value;
 -(void)showProgressDialog: (NSValue *)o_value;
 -(IBAction)progDialogAction:(id)sender;
--(BOOL)progressCancelled;
 -(void)updateProgressPanelWithText: (NSString *)string andNumber: (double)d_number;
 -(void)destroyProgressPanel;
 
index fd51456e8828ec4d3f771a5801b63cc7c9f0ad21..af438eb16df00984e7d26b5180cc460b4312fc72 100644 (file)
@@ -36,6 +36,8 @@
 
 static VLCCoreDialogProvider *_o_sharedInstance = nil;
 
+@synthesize progressCancelled=b_progress_cancelled;
+
 + (VLCCoreDialogProvider *)sharedInstance
 {
     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
@@ -153,10 +155,10 @@ static VLCCoreDialogProvider *_o_sharedInstance = nil;
 {
     /* we work-around a Cocoa limitation here, since you cannot delay an execution
      * on the main thread within a single call */
-    b_progress_cancelled = NO;
+    [self setProgressCancelled:NO];
 
     dialog_progress_bar_t *p_dialog = [o_value pointerValue];
-    if (!p_dialog || b_progress_cancelled)
+    if (!p_dialog)
         return;
 
     [o_prog_win setTitle: toNSStr(p_dialog->title)];
@@ -177,7 +179,7 @@ static VLCCoreDialogProvider *_o_sharedInstance = nil;
 {
     dialog_progress_bar_t *p_dialog = [o_value pointerValue];
 
-    if (!p_dialog || b_progress_cancelled)
+    if (!p_dialog || [self progressCancelled])
         return;
 
     [o_prog_bar setDoubleValue: 0];
@@ -197,19 +199,14 @@ static VLCCoreDialogProvider *_o_sharedInstance = nil;
 
 -(void)destroyProgressPanel
 {
-    b_progress_cancelled = YES;
+    [self setProgressCancelled:YES];
     [o_prog_bar performSelectorOnMainThread:@selector(stopAnimation:) withObject:self waitUntilDone:YES];
     [o_prog_win performSelectorOnMainThread:@selector(close) withObject:nil waitUntilDone:YES];
 }
 
 -(IBAction)progDialogAction:(id)sender
 {
-    b_progress_cancelled = YES;
-}
-
--(BOOL)progressCancelled
-{
-    return b_progress_cancelled;
+    [self setProgressCancelled:YES];
 }
 
 -(id)errorPanel
index db4e72149fe4e2158aeb887a77679b2241044884..7ff668c158815214990040f08f24fb80c3fe5b8f 100644 (file)
@@ -524,13 +524,10 @@ void updateProgressPanel (void *priv, const char *text, float value)
 {
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
 
-    NSString *o_txt;
-    if (text != NULL)
-        o_txt = [NSString stringWithUTF8String:text];
-    else
-        o_txt = @"";
-
-    [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
+    NSString *o_txt = toNSStr(text);
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
+    });
 
     [o_pool release];
 }