[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [25095] trunk/blender: Quicktime Carbon: Fix memory leak when build with cocoa

Damien Plisson damien.plisson at yahoo.fr
Thu Dec 3 13:16:02 CET 2009


Revision: 25095
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=25095
Author:   damien78
Date:     2009-12-03 13:16:00 +0100 (Thu, 03 Dec 2009)

Log Message:
-----------
Quicktime Carbon: Fix memory leak when build with cocoa

Modified Paths:
--------------
    trunk/blender/intern/ghost/CMakeLists.txt
    trunk/blender/intern/ghost/SConscript
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
    trunk/blender/source/blender/quicktime/SConscript
    trunk/blender/source/blender/quicktime/apple/quicktime_export.c

Modified: trunk/blender/intern/ghost/CMakeLists.txt
===================================================================
--- trunk/blender/intern/ghost/CMakeLists.txt	2009-12-03 10:27:22 UTC (rev 25094)
+++ trunk/blender/intern/ghost/CMakeLists.txt	2009-12-03 12:16:00 UTC (rev 25095)
@@ -45,6 +45,10 @@
 	LIST(REMOVE_ITEM SRC "${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_DisplayManagerX11.cpp")
 	LIST(REMOVE_ITEM SRC "${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_SystemX11.cpp")
 	LIST(REMOVE_ITEM SRC "${CMAKE_CURRENT_SOURCE_DIR}/intern/GHOST_WindowX11.cpp")
+
+	IF(WITH_QUICKTIME)
+		ADD_DEFINITIONS(-DWITH_QUICKTIME)
+	ENDIF(WITH_QUICKTIME)
 ELSE(APPLE)
 	IF(WIN32)
 		SET(INC ${INC} ${WINTAB_INC})

Modified: trunk/blender/intern/ghost/SConscript
===================================================================
--- trunk/blender/intern/ghost/SConscript	2009-12-03 10:27:22 UTC (rev 25094)
+++ trunk/blender/intern/ghost/SConscript	2009-12-03 12:16:00 UTC (rev 25095)
@@ -12,6 +12,7 @@
 
 
 pf = ['GHOST_DisplayManager', 'GHOST_System', 'GHOST_Window', 'GHOST_DropTarget']
+defs=['_USE_MATH_DEFINES']
 
 if window_system in ('linux2', 'openbsd3', 'sunos5', 'freebsd6', 'irix6'):
 	for f in pf:
@@ -29,6 +30,10 @@
 			pass
 elif window_system == 'darwin':
 	if env['WITH_GHOST_COCOA']:
+		if env['WITH_BF_QUICKTIME']:
+			defs.append('WITH_QUICKTIME')
+		if env['USE_QTKIT']:
+			defs.append('USE_QTKIT')
 		for f in pf:
 			try:
 				sources.remove('intern' + os.sep + f + 'Win32.cpp')
@@ -49,7 +54,6 @@
 	print "Unknown window system specified."
 	Exit()
 
-defs=['_USE_MATH_DEFINES']
 if env['BF_GHOST_DEBUG']:
 	defs.append('BF_GHOST_DEBUG')
 	

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2009-12-03 10:27:22 UTC (rev 25094)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2009-12-03 12:16:00 UTC (rev 25095)
@@ -389,7 +389,29 @@
 	}
 }
 
+#if defined(WITH_QUICKTIME) && !defined(USE_QTKIT)
+//Need to place this quicktime function in an ObjC file
+//It is used to avoid memory leak when raising the quicktime "compression settings" standard dialog
+extern "C" {
+	struct bContext;
+	struct wmOperator;
+	extern int fromcocoa_request_qtcodec_settings(bContext *C, wmOperator *op);
 
+
+int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
+{
+	int result;
+	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+	
+	result = fromcocoa_request_qtcodec_settings(C, op);
+	
+	[pool drain];
+	return result;
+}
+};
+#endif
+
+
 #pragma mark Cocoa objects
 
 /**

Modified: trunk/blender/source/blender/quicktime/SConscript
===================================================================
--- trunk/blender/source/blender/quicktime/SConscript	2009-12-03 10:27:22 UTC (rev 25094)
+++ trunk/blender/source/blender/quicktime/SConscript	2009-12-03 12:16:00 UTC (rev 25095)
@@ -30,4 +30,9 @@
 types = ['core','player']
 priorities = [200,235]
 
-env.BlenderLib ('bf_quicktime', sources=source_files, includes=incs, defines=['WITH_QUICKTIME'], libtype=types, priority=priorities)
+defs=['WITH_QUICKTIME']
+
+if env['WITH_GHOST_COCOA']:
+	defs.append('GHOST_COCOA')
+
+env.BlenderLib ('bf_quicktime', sources=source_files, includes=incs, defines=defs, libtype=types, priority=priorities)

Modified: trunk/blender/source/blender/quicktime/apple/quicktime_export.c
===================================================================
--- trunk/blender/source/blender/quicktime/apple/quicktime_export.c	2009-12-03 10:27:22 UTC (rev 25094)
+++ trunk/blender/source/blender/quicktime/apple/quicktime_export.c	2009-12-03 12:16:00 UTC (rev 25095)
@@ -783,7 +783,7 @@
 	err = SCRequestSequenceSettings(qtdata->theComponent);
  
 	if (err == scUserCancelled) {
-		return 0;
+		return OPERATOR_FINISHED;
 	}
 
 		// update runtime codecsettings for use with the codec dialog
@@ -844,7 +844,7 @@
 		}
 	}
 
-	return 1;
+	return OPERATOR_FINISHED;
 }
 
 static int ED_operator_setqtcodec(bContext *C)
@@ -852,7 +852,18 @@
 	return G.have_quicktime != FALSE;
 }
 
+#if defined(__APPLE__) && defined(GHOST_COCOA)
+//Need to set up a Cocoa NSAutoReleasePool to avoid memory leak
+//And it must be done in an objC file, so use a GHOST_SystemCocoa.mm function for that
+extern int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op);
 
+int fromcocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
+{
+	return request_qtcodec_settings(C, op);
+}
+#endif
+
+
 void SCENE_OT_render_data_set_quicktime_codec(wmOperatorType *ot)
 {
 	/* identifiers */
@@ -861,7 +872,11 @@
     ot->idname= "SCENE_OT_render_data_set_quicktime_codec";
 	
     /* api callbacks */
+#if defined(__APPLE__) && defined(GHOST_COCOA)
+	ot->exec = cocoa_request_qtcodec_settings;
+#else
     ot->exec= request_qtcodec_settings;
+#endif
     ot->poll= ED_operator_setqtcodec;
 	
     /* flags */





More information about the Bf-blender-cvs mailing list