Fix for [#23753]: Enable QTKit import to run in background thread
authorDamien Plisson <damien.plisson@yahoo.fr>
Sat, 18 Sep 2010 12:50:45 +0000 (12:50 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Sat, 18 Sep 2010 12:50:45 +0000 (12:50 +0000)
Was crashing file browser when there was some quicktime movies in the folder

source/blender/quicktime/apple/qtkit_import.m

index 80b97066b6138bd161c25506282fcc5a5e17c4d3..41c4e0cc5a373151a4cfb266e2d1f85a7e9cd1c1 100644 (file)
@@ -30,6 +30,8 @@
  */
 #ifdef WITH_QUICKTIME
 
+#include "MEM_guardedalloc.h"
+
 #include "IMB_anim.h"
 #include "BLO_sys_types.h"
 #include "BKE_global.h"
@@ -113,6 +115,8 @@ int anim_is_quicktime (char *name)
 
 
 void free_anim_quicktime (struct anim *anim) {
+       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+       
        if (anim == NULL) return;
        if (anim->qtime == NULL) return;
 
@@ -122,11 +126,15 @@ void free_anim_quicktime (struct anim *anim) {
        [anim->qtime->media release];
        [anim->qtime->movie release];
 
+       [QTMovie exitQTKitOnThread];
+
        if(anim->qtime) MEM_freeN (anim->qtime);
 
        anim->qtime = NULL;
 
        anim->duration = 0;
+
+       [pool drain];
 }
 
 static ImBuf * nsImageToiBuf(NSImage *sourceImage, int width, int height)
@@ -302,6 +310,8 @@ int startquicktime (struct anim *anim)
 
        pool = [[NSAutoreleasePool alloc] init];
        
+       [QTMovie enterQTKitOnThread];           
+
        attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSString stringWithCString:anim->name 
                                                                         encoding:[NSString defaultCStringEncoding]], QTMovieFileNameAttribute,
@@ -314,6 +324,7 @@ int startquicktime (struct anim *anim)
                if(QTIME_DEBUG) printf("qt: bad movie %s\n", anim->name);
                MEM_freeN(anim->qtime);
                if(QTIME_DEBUG) printf("qt: can't load %s\n", anim->name);
+               [QTMovie exitQTKitOnThread];
                [pool drain];
                return -1;
        }
@@ -328,6 +339,7 @@ int startquicktime (struct anim *anim)
                [anim->qtime->movie release];
                MEM_freeN(anim->qtime);
                if(QTIME_DEBUG) printf("qt: can't load %s\n", anim->name);
+               [QTMovie exitQTKitOnThread];
                [pool drain];
                return -1;
        }