[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48147] trunk/blender/source: Fix for [ #31396] "bge.logic.LibLoad fails to import text blocks" reported by Leonard Ritter.

Mitchell Stokes mogurijin at gmail.com
Thu Jun 21 07:41:15 CEST 2012


Revision: 48147
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48147
Author:   moguri
Date:     2012-06-21 05:41:06 +0000 (Thu, 21 Jun 2012)
Log Message:
-----------
Fix for [#31396] "bge.logic.LibLoad fails to import text blocks" reported by Leonard Ritter.

Blender's import function check's the Text datablocks in main for additional modules for importing. However, libloaded scenes were 1) not loading Text datablocks and 2) not letting bpy know about them. Text datablocks are now loaded if a Scene is loaded and bpy can now looking through extra Mains to find additional modules.

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/bpy_internal_import.c
    trunk/blender/source/blender/python/generic/bpy_internal_import.h
    trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h

Modified: trunk/blender/source/blender/python/generic/bpy_internal_import.c
===================================================================
--- trunk/blender/source/blender/python/generic/bpy_internal_import.c	2012-06-21 05:30:57 UTC (rev 48146)
+++ trunk/blender/source/blender/python/generic/bpy_internal_import.c	2012-06-21 05:41:06 UTC (rev 48147)
@@ -52,6 +52,7 @@
 #include "BKE_main.h"
 
 static Main *bpy_import_main = NULL;
+static ListBase bpy_import_main_list;
 
 /* 'builtins' is most likely PyEval_GetBuiltins() */
 void bpy_import_init(PyObject *builtins)
@@ -92,6 +93,16 @@
 	bpy_import_main = maggie;
 }
 
+void bpy_import_main_extra_add(struct Main *maggie)
+{
+	BLI_addhead(&bpy_import_main_list, maggie);
+}
+
+void bpy_import_main_extra_remove(struct Main *maggie)
+{
+	BLI_remlink_safe(&bpy_import_main_list, maggie);
+}
+
 /* returns a dummy filename for a textblock so we can tell what file a text block comes from */
 void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
 {
@@ -150,6 +161,18 @@
 
 	text = BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
 
+	if (text) {
+		*found = 1;
+		return bpy_text_import(text);
+	}
+
+	/* If we still haven't found the module try additional modules form bpy_import_main_list */
+	maggie = bpy_import_main_list.first;
+	while (maggie && !text) {
+		text = BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
+		maggie = maggie->next;
+	}
+
 	if (!text)
 		return NULL;
 	else

Modified: trunk/blender/source/blender/python/generic/bpy_internal_import.h
===================================================================
--- trunk/blender/source/blender/python/generic/bpy_internal_import.h	2012-06-21 05:30:57 UTC (rev 48146)
+++ trunk/blender/source/blender/python/generic/bpy_internal_import.h	2012-06-21 05:41:06 UTC (rev 48147)
@@ -62,4 +62,8 @@
 struct Main *bpy_import_main_get(void);
 void bpy_import_main_set(struct Main *maggie);
 
+/* This is used for importing text from dynamically loaded libraries in the game engine */
+void bpy_import_main_extra_add(struct Main *maggie);
+void bpy_import_main_extra_remove(struct Main *maggie);
+
 #endif				/* __BPY_INTERNAL_IMPORT_H__ */

Modified: trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp	2012-06-21 05:30:57 UTC (rev 48146)
+++ trunk/blender/source/gameengine/Converter/KX_BlenderSceneConverter.cpp	2012-06-21 05:41:06 UTC (rev 48147)
@@ -42,6 +42,7 @@
 #include "KX_PhysicsEngineEnums.h"
 #include "PHY_IPhysicsEnvironment.h"
 #include "KX_KetsjiEngine.h"
+#include "KX_PythonInit.h" // So we can handle adding new text datablocks for Python to import
 #include "KX_IPhysicsController.h"
 #include "BL_Material.h"
 #include "BL_ActionActuator.h"
@@ -173,9 +174,9 @@
 #endif
 
 	/* free any data that was dynamically loaded */
-	for (vector<Main*>::iterator it=m_DynamicMaggie.begin(); !(it==m_DynamicMaggie.end()); it++) {
-		Main *main= *it;
-		free_main(main);
+	while (m_DynamicMaggie.size() != 0)
+	{
+		FreeBlendFile(m_DynamicMaggie[0]);
 	}
 
 	m_DynamicMaggie.clear();
@@ -987,6 +988,11 @@
 
 	load_datablocks(main_newlib, bpy_openlib, path, idcode);
 
+	if (idcode==ID_SCE) {
+		/* assume we want text blocks too */
+		load_datablocks(main_newlib, bpy_openlib, path, ID_TXT);
+	}
+
 	/* now do another round of linking for Scenes so all actions are properly loaded */
 	if (idcode==ID_SCE && options & LIB_LOAD_LOAD_ACTIONS) {
 		load_datablocks(main_newlib, bpy_openlib, path, ID_AC);
@@ -1038,6 +1044,10 @@
 			delete other;
 		}
 
+		/* Handle any text datablocks */
+
+		addImportMain(main_newlib);
+
 		/* Now handle all the actions */
 		if (options & LIB_LOAD_LOAD_ACTIONS) {
 			ID *action;
@@ -1330,6 +1340,9 @@
 		}
 	}
 
+	/* make sure this maggie is removed from the import list if it's there (this operation is safe if it isn't in the list) */
+	removeImportMain(maggie);
+
 	free_main(maggie);
 
 	return true;

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2012-06-21 05:30:57 UTC (rev 48146)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2012-06-21 05:41:06 UTC (rev 48147)
@@ -1821,6 +1821,16 @@
 //	PyObject_Print(sys_path, stderr, 0);
 }
 
+void addImportMain(struct Main *maggie)
+{
+	bpy_import_main_extra_add(maggie);
+}
+
+void removeImportMain(struct Main *maggie)
+{
+	bpy_import_main_extra_remove(maggie);
+}
+
 // Copied from bpy_interface.c
 static struct _inittab bge_internal_modules[]= {
 	{(char *)"mathutils", PyInit_mathutils},

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h	2012-06-21 05:30:57 UTC (rev 48146)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.h	2012-06-21 05:41:06 UTC (rev 48147)
@@ -61,6 +61,9 @@
 int			loadGamePythonConfig(char *marshal_buffer, int marshal_length);
 #endif
 
+void addImportMain(struct Main *maggie);
+void removeImportMain(struct Main *maggie);
+
 class KX_KetsjiEngine;
 class KX_Scene;
 




More information about the Bf-blender-cvs mailing list