[vlc-commits] macosx: Spin event loop to process pending selectors on main thread

David Fuhrmann git at videolan.org
Sun Feb 18 19:44:24 CET 2018


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sun Feb 18 19:16:57 2018 +0100| [5d0d2b0d533df40c6e78460d2a320997e7e3ee34] | committer: David Fuhrmann

macosx: Spin event loop to process pending selectors on main thread

This is needed to cleanup everything correctly. In one particular
occurence, the InputManager still had pending selectors in the queue
which prevented the object from being released.
This resulted in playback position never saved, which is fixed now
with this change.

Also this fixes occasional crashes in debug mode as the ref count of
the current input thread is now correct on exit.

fixes #19704

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

 modules/gui/macosx/VLCMain.m | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/modules/gui/macosx/VLCMain.m b/modules/gui/macosx/VLCMain.m
index 7763f12f73..511a140a8b 100644
--- a/modules/gui/macosx/VLCMain.m
+++ b/modules/gui/macosx/VLCMain.m
@@ -115,6 +115,16 @@ void CloseIntf (vlc_object_t *p_this)
         [[VLCMain sharedInstance] applicationWillTerminate:nil];
         [VLCMain killInstance];
 
+        /*
+         * Spinning the event loop here is important to help cleaning up all objects which should be
+         * destroyed here. Its possible that main thread selectors (which hold a strong reference
+         * to the target object), are still in the queue (e.g. fired from variable callback).
+         * Thus make sure those are still dispatched and the references to the targets are
+         * cleared, to allow the objects to be released.
+         */
+        msg_Dbg(p_this, "Spin the event loop to clean up the interface");
+        [[NSRunLoop mainRunLoop] runUntilDate:[NSDate date]];
+
         p_interface_thread = nil;
     }
 }
@@ -322,6 +332,7 @@ static VLCMain *sharedInstance = nil;
 
 - (void)applicationWillTerminate:(NSNotification *)notification
 {
+    msg_Dbg(getIntf(), "applicationWillTerminate called");
     if (b_intf_terminating)
         return;
     b_intf_terminating = true;
@@ -342,8 +353,6 @@ static VLCMain *sharedInstance = nil;
     config_PutInt(p_intf, "loop", var_GetBool(p_playlist, "loop"));
     config_PutInt(p_intf, "repeat", var_GetBool(p_playlist, "repeat"));
 
-    msg_Dbg(p_intf, "Terminating");
-
     var_DelCallback(p_intf->obj.libvlc, "intf-toggle-fscontrol", ShowController, (__bridge void *)self);
     var_DelCallback(p_intf->obj.libvlc, "intf-show", ShowController, (__bridge void *)self);
 



More information about the vlc-commits mailing list