From 1d11db6596cc985050dec3b337e36b0939fa1966 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 29 May 2013 21:43:21 +0200 Subject: macosx_application: use @autoreleasepool I don't even want to know how this worked. It scares me a lot. --- osdep/macosx_application.h | 2 -- osdep/macosx_application.m | 58 ++++++++++++++++++++-------------------------- 2 files changed, 25 insertions(+), 35 deletions(-) (limited to 'osdep') diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index 13a63bc50f..372a57a566 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -41,8 +41,6 @@ void cocoa_register_menu_item_action(MPMenuKey key, void* action); // initializes Cocoa application void init_cocoa_application(void); void terminate_cocoa_application(void); -void cocoa_autorelease_pool_alloc(void); -void cocoa_autorelease_pool_drain(void); // Runs the Cocoa Main Event Loop void cocoa_run_runloop(void); diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 6d2d5e03e2..f182a2643d 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -28,7 +28,6 @@ #include "video/out/osx_common.h" static Application *app; -static NSAutoreleasePool *pool; static pthread_t playback_thread_id; @interface Application (PrivateMethods) @@ -258,31 +257,35 @@ struct playback_thread_ctx { static void *playback_thread(void *ctx_obj) { - struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj; - ctx->mpv_main(*ctx->argc, *ctx->argv); - cocoa_stop_runloop(); - pthread_exit(NULL); + @autoreleasepool { + struct playback_thread_ctx *ctx = (struct playback_thread_ctx*) ctx_obj; + ctx->mpv_main(*ctx->argc, *ctx->argv); + cocoa_stop_runloop(); + pthread_exit(NULL); + } } int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]) { - struct playback_thread_ctx ctx = {0}; - ctx.mpv_main = mpv_main; - ctx.argc = &argc; - ctx.argv = &argv; - - init_cocoa_application(); - macosx_finder_args_preinit(&argc, &argv); - pthread_create(&playback_thread_id, NULL, playback_thread, &ctx); - cocoa_run_runloop(); - - // This should never be reached: cocoa_run_runloop blocks until the process - // is quit - mp_msg(MSGT_CPLAYER, MSGL_ERR, "There was either a problem initializing " - "Cocoa or the Runloop was stopped unexpectedly. Please report this " - "issues to a developer.\n"); - pthread_join(playback_thread_id, NULL); - return 1; + @autoreleasepool { + struct playback_thread_ctx ctx = {0}; + ctx.mpv_main = mpv_main; + ctx.argc = &argc; + ctx.argv = &argv; + + init_cocoa_application(); + macosx_finder_args_preinit(&argc, &argv); + pthread_create(&playback_thread_id, NULL, playback_thread, &ctx); + cocoa_run_runloop(); + + // This should never be reached: cocoa_run_runloop blocks until the + // process is quit + mp_msg(MSGT_CPLAYER, MSGL_ERR, "There was either a problem " + "initializing Cocoa or the Runloop was stopped unexpectedly. " + "Please report this issues to a developer.\n"); + pthread_join(playback_thread_id, NULL); + return 1; + } } void cocoa_register_menu_item_action(MPMenuKey key, void* action) @@ -312,17 +315,6 @@ void terminate_cocoa_application(void) [NSApp terminate:app]; } -void cocoa_autorelease_pool_alloc(void) -{ - pool = [[NSAutoreleasePool alloc] init]; -} - -void cocoa_autorelease_pool_drain(void) -{ - [pool drain]; -} - - void cocoa_run_runloop() { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; -- cgit v1.2.3