diff options
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 5 | ||||
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 96 |
2 files changed, 72 insertions, 29 deletions
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 8922846f365..fe47fa3c60e 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -720,8 +720,9 @@ void GPU_free_images(void) { 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 */ diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 3a9e59c3c25..0b4fde61e1c 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -198,7 +198,53 @@ void usage(char* program) 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 @@ char *get_filename(int argc, char **argv) { */ 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 @@ char *get_filename(int argc, char **argv) { 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 @@ int main(int argc, char** argv) 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 @@ int main(int argc, char** argv) } 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 @@ int main(int argc, char** argv) 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); } |