]> git.sesse.net Git - vlc/blobdiff - modules/gui/minimal_macosx/VLCOpenGLVoutView.m
minimal_macosx: Don't attempt to use the vout when there is none.
[vlc] / modules / gui / minimal_macosx / VLCOpenGLVoutView.m
index 31e53d06439645623b37d6af17481dc968312baa..8b50b4250c9c21b198e5e16991735bbbcbbb2314 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * VLCOpenGLVoutView.m: MacOS X OpenGL provider
  *****************************************************************************
- * Copyright (C) 2001-2007 the VideoLAN team
+ * Copyright (C) 2001-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Colin Delacroix <colin@zoy.org>
@@ -49,12 +49,12 @@ int cocoaglvoutviewInit( vout_thread_t * p_vout )
 
     msg_Dbg( p_vout, "Mac OS X Vout is opening" );
 
-    var_Create( p_vout, "drawable", VLC_VAR_DOINHERIT );
-    var_Get( p_vout, "drawable", &value_drawable );
+    var_Create( p_vout, "drawable-nsobject", VLC_VAR_DOINHERIT );
+    var_Get( p_vout, "drawable-nsobject", &value_drawable );
 
     p_vout->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
 
-    o_cocoaglview_container = (id) value_drawable.i_int;
+    o_cocoaglview_container = (id) value_drawable.p_address;
     if (!o_cocoaglview_container)
     {
         msg_Warn( p_vout, "No drawable!, spawing a window" );
@@ -80,8 +80,11 @@ void cocoaglvoutviewEnd( vout_thread_t * p_vout )
 {
     id <VLCOpenGLVoutEmbedding> o_cocoaglview_container;
 
+    if (!p_vout->p_sys->o_glview)
+        return;
+
     msg_Dbg( p_vout, "Mac OS X Vout is closing" );
-    var_Destroy( p_vout, "drawable" );
+    var_Destroy( p_vout, "drawable-nsobject" );
 
     o_cocoaglview_container = [p_vout->p_sys->o_glview container];
 
@@ -89,15 +92,15 @@ void cocoaglvoutviewEnd( vout_thread_t * p_vout )
     [p_vout->p_sys->o_glview detachFromVout];
     msg_Dbg( p_vout, "Mac OS X Vout is closing" );
 
-    /* Let the view go, _without_blocking_ */
-    [p_vout->p_sys->o_glview performSelectorOnMainThread:@selector(removeFromSuperview) withObject:NULL waitUntilDone:NO];
-
     if( [(id)o_cocoaglview_container respondsToSelector:@selector(removeVoutSubview:)] )
-        [o_cocoaglview_container removeVoutSubview: p_vout->p_sys->o_glview];
+        [o_cocoaglview_container performSelectorOnMainThread:@selector(removeVoutSubview:) withObject:p_vout->p_sys->o_glview waitUntilDone:NO];
 
-    [p_vout->p_sys->o_glview release];
+    /* Let the view go and release it, _without_blocking_ */
+    [p_vout->p_sys->o_glview performSelectorOnMainThread:@selector(removeFromSuperviewAndRelease) withObject:nil waitUntilDone:NO];
+    p_vout->p_sys->o_glview = nil;
 
     [p_vout->p_sys->o_pool release];
+    p_vout->p_sys->o_pool = nil;
  
 }
 
@@ -151,10 +154,8 @@ int cocoaglvoutviewControl( vout_thread_t *p_vout, int i_query, va_list args )
             [[p_vout->p_sys->o_glview container] setOnTop: b_arg];
             return VLC_SUCCESS;
 
-        case VOUT_CLOSE:
-        case VOUT_REPARENT:
         default:
-            return vout_vaControlDefault( p_vout, i_query, args );
+            return VLC_EGENERIC;
     }
 }
 
@@ -221,12 +222,12 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
     [super dealloc];
 }
 
-- (void)removeFromSuperview
+- (void)removeFromSuperviewAndRelease
 {
-    [super removeFromSuperview];
+    [self removeFromSuperview];
+    [self release];
 }
 
-
 - (id) initWithVout: (vout_thread_t *) vout container: (id <VLCOpenGLVoutEmbedding>) aContainer
 {
     NSOpenGLPixelFormatAttribute attribs[] =
@@ -359,6 +360,8 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
 
 - (void) update
 {
+    if (!p_vout)
+        return;
     if( kCGLNoError != CGLLockContext([[self openGLContext] CGLContextObj]) )
         return;
     [super update];
@@ -367,6 +370,8 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
 
 - (void) drawRect: (NSRect) rect
 {
+    if (!p_vout)
+        return;
     if( kCGLNoError != CGLLockContext([[self openGLContext] CGLContextObj]) )
         return;
     [[self openGLContext] flushBuffer];