[vlc-commits] macosx: Update progress dialog on the main thread, make check thread safe

David Fuhrmann git at videolan.org
Sat Mar 21 17:35:52 CET 2015


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Mar 21 17:31:20 2015 +0100| [984aadb5ca4f9a8bf01dffae42440320a1ea0f13] | committer: David Fuhrmann

macosx: Update progress dialog on the main thread, make check thread safe

This should fix some crashes as reported by the users.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=984aadb5ca4f9a8bf01dffae42440320a1ea0f13
---

 modules/gui/macosx/coredialogs.h |    3 ++-
 modules/gui/macosx/coredialogs.m |   17 +++++++----------
 modules/gui/macosx/intf.m        |   11 ++++-------
 3 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/modules/gui/macosx/coredialogs.h b/modules/gui/macosx/coredialogs.h
index 239600b..2c96247 100644
--- a/modules/gui/macosx/coredialogs.h
+++ b/modules/gui/macosx/coredialogs.h
@@ -76,6 +76,8 @@
 }
 + (VLCCoreDialogProvider *)sharedInstance;
 
+ at 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;
 
diff --git a/modules/gui/macosx/coredialogs.m b/modules/gui/macosx/coredialogs.m
index fd51456..af438eb 100644
--- a/modules/gui/macosx/coredialogs.m
+++ b/modules/gui/macosx/coredialogs.m
@@ -36,6 +36,8 @@
 
 static VLCCoreDialogProvider *_o_sharedInstance = nil;
 
+ at 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
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index db4e721..7ff668c 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -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];
 }



More information about the vlc-commits mailing list