Merging r58362 through r58463 from trunk into soc-2013-depsgraph_mt
[blender.git] / source / gameengine / GamePlayer / ghost / GPG_ghost.cpp
index 69137bc7842ea1ac34aea88ee4635df2f87479e6..46e23529be4f9a4a7b28a086d9b3c1c471a178b8 100644 (file)
@@ -1033,10 +1033,9 @@ int main(int argc, char** argv)
                                                 * removal is needed else the system will free an already freed value */
                                                system->removeEventConsumer(&app);
 
-                                               /* nodesystem relies on blendfile data, free it first */
-                                               free_nodesystem();
-
                                                BLO_blendfiledata_free(bfd);
+                                               /* G.main == bfd->main, it gets referenced in free_nodesystem so we can't have a dangling pointer */
+                                               G.main = NULL;
                                                if (python_main) MEM_freeN(python_main);
                                        }
                                } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
@@ -1054,6 +1053,13 @@ int main(int argc, char** argv)
                }
        }
 
+       /* refer to WM_exit_ext() and free_blender(),
+        * these are not called in the player but we need to match some of there behavior here,
+        * if the order of function calls or blenders state isn't matching that of blender proper,
+        * we may get troubles later on */
+
+       free_nodesystem();
+
        // Cleanup
        RNA_exit();
        BLF_exit();