[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16492] trunk/blender/source:

Brecht Van Lommel brechtvanlommel at pandora.be
Fri Sep 12 18:06:18 CEST 2008


Revision: 16492
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16492
Author:   blendix
Date:     2008-09-12 18:06:17 +0200 (Fri, 12 Sep 2008)

Log Message:
-----------

Fixes for game engine runtime on Mac OS X, there were issues
working with relative paths. Still doesn't work optimal, since
paths are relative to game.blend which is in the app bundle
under Contents/Resources, so other files need to be moved there
manually at the moment.

Modified Paths:
--------------
    trunk/blender/source/blender/gpu/intern/gpu_draw.c
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp

Modified: trunk/blender/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_draw.c	2008-09-12 15:26:00 UTC (rev 16491)
+++ trunk/blender/source/blender/gpu/intern/gpu_draw.c	2008-09-12 16:06:17 UTC (rev 16492)
@@ -720,8 +720,9 @@
 {
 	Image* ima;
 
-	for(ima=G.main->image.first; ima; ima=ima->id.next)
-		GPU_free_image(ima);
+	if(G.main)
+		for(ima=G.main->image.first; ima; ima=ima->id.next)
+			GPU_free_image(ima);
 }
 
 /* OpenGL Materials */

Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp	2008-09-12 15:26:00 UTC (rev 16491)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp	2008-09-12 16:06:17 UTC (rev 16492)
@@ -198,7 +198,53 @@
 	printf("example: %s -g show_framerate = 0 c:\\loadtest.blend\n", program);
 }
 
-char *get_filename(int argc, char **argv) {
+static void make_absolute_filename(char *blendfilename)
+{
+	int abs = 0;
+	int filelen;
+	char cwd[FILE_MAXDIR + FILE_MAXFILE];
+	char filename[FILE_MAXDIR + FILE_MAXFILE];
+
+	cwd[0] = filename[0] = '\0';
+	
+	BLI_strncpy(filename, blendfilename, sizeof(filename));
+	filelen = strlen(filename);
+	
+	/* relative path checks, could do more tests here... */
+#ifdef WIN32
+	/* Account for X:/ and X:\ - should be enough */
+	if (filelen >= 3 && filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/'))
+		abs = 1;
+#else
+	if (filelen >= 2 && filename[0] == '/')
+		abs = 1	;
+#endif
+	if (!abs) {
+		BLI_getwdN(cwd); /* incase the full path to the blend isnt used */
+		
+		if (cwd[0] == '\0') {
+			printf(
+			"Could not get the current working directory - $PWD for an unknown reason.\n\t"
+			"Relative linked files will not load if the entire blend path is not used.\n\t"
+			"The 'Play' button may also fail.\n"
+			);
+		} else {
+			/* uses the blend path relative to cwd important for loading relative linked files.
+			*
+			* cwd should contain c:\ etc on win32 so the relbase can be NULL
+			* relbase being NULL also prevents // being misunderstood as relative to the current
+			* blend file which isnt a feature we want to use in this case since were dealing
+			* with a path from the command line, rather then from inside Blender */
+			
+			BLI_make_file_string(NULL, filename, cwd, blendfilename);
+		}
+	}
+
+	BLI_strncpy(blendfilename, filename, sizeof(filename));
+}
+
+static void get_filename(int argc, char **argv, char *filename)
+{
 #ifdef __APPLE__
 /* On Mac we park the game file (called game.blend) in the application bundle.
 * The executable is located in the bundle as well.
@@ -206,22 +252,18 @@
 	*/
 	int srclen = ::strlen(argv[0]);
 	int len = 0;
-	char *filename = NULL;
+	char *gamefile = NULL;
 	
+	filename[0] = '\0';
+
 	if (argc > 1) {
 		if (BLI_exists(argv[argc-1])) {
-			len = ::strlen(argv[argc-1]);
-			filename = new char [len + 1];
-			::strcpy(filename, argv[argc-1]);
-			return(filename);
+			BLI_strncpy(filename, argv[argc-1], FILE_MAXDIR + FILE_MAXFILE);
 		}
 		if (::strncmp(argv[argc-1], "-psn_", 5)==0) {
 			static char firstfilebuf[512];
 			if (GHOST_HACK_getFirstFile(firstfilebuf)) {
-				len = ::strlen(firstfilebuf);
-				filename = new char [len + 1];
-				::strcpy(filename, firstfilebuf);
-				return(filename);
+				BLI_strncpy(filename, firstfilebuf, FILE_MAXDIR + FILE_MAXFILE);
 			}
 		}                        
 	}
@@ -229,23 +271,26 @@
 	srclen -= ::strlen("MacOS/blenderplayer");
 	if (srclen > 0) {
 		len = srclen + ::strlen("Resources/game.blend"); 
-		filename = new char [len + 1];
-		::strcpy(filename, argv[0]);
-		::strcpy(filename + srclen, "Resources/game.blend");
+		gamefile = new char [len + 1];
+		::strcpy(gamefile, argv[0]);
+		::strcpy(gamefile + srclen, "Resources/game.blend");
 		//::printf("looking for file: %s\n", filename);
 		
-		if (BLI_exists(filename)) {
-			return (filename);
-		}
+		if (BLI_exists(gamefile))
+			BLI_strncpy(filename, gamefile, FILE_MAXDIR + FILE_MAXFILE);
+
+		delete gamefile;
 	}
 	
-	return(NULL);
 #else
-	return (argc>1)?argv[argc-1]:NULL;
+	filename[0] = '\0';
+
+	if(argc > 1)
+		BLI_strncpy(filename, argv[argc-1], FILE_MAXDIR + FILE_MAXFILE);
 #endif // !_APPLE
 }
 
-static BlendFileData *load_game_data(char *progname, char *filename = NULL) {
+static BlendFileData *load_game_data(char *progname, char *filename = NULL, char *relativename = NULL) {
 	BlendReadError error;
 	BlendFileData *bfd = NULL;
 	
@@ -579,9 +624,12 @@
 				STR_String exitstring = "";
 				GPG_Application app(system);
 				bool firstTimeRunning = true;
-				char *filename = get_filename(argc, argv);
+				char filename[FILE_MAXDIR + FILE_MAXFILE];
 				char *titlename;
 				char pathname[160];
+
+				get_filename(argc, argv, filename);
+				make_absolute_filename(filename);
 				
 				do
 				{
@@ -613,7 +661,7 @@
 					}
 					else
 					{
-						bfd = load_game_data(bprogname, filename);
+						bfd = load_game_data(bprogname, filename[0]? filename: NULL);
 					}
 					
 					//::printf("game data loaded from %s\n", filename);
@@ -782,12 +830,6 @@
 						pyGlobalDictString_Length = app.GetPyGlobalDictMarshalLength();
 						
 						BLO_blendfiledata_free(bfd);
-						
-#ifdef __APPLE__
-						if (filename) {
-							delete [] filename;
-						}
-#endif // __APPLE__
 					}
 				} while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
 			}





More information about the Bf-blender-cvs mailing list