Skip to content

Commit

Permalink
UPBGE: Fix relative path when using startGame.
Browse files Browse the repository at this point in the history
Previously the 0.0.7 the G.main->name was set to the name
of the next loaded game when using the python function startGame.
This was removed in the refactor of the launchers and caused that
image and other data loading using G.main->name to resolve
relative path were not working anymore.
To fix this issue the change of G.main is restored.

Fix issue: #563.
  • Loading branch information
panzergame committed Aug 25, 2017
1 parent 16fff9b commit 2a72166
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
extern "C" {
# include "DNA_scene_types.h"

# include "BKE_global.h"
# include "BKE_report.h"
# include "BKE_main.h"
# include "BKE_context.h"
Expand Down Expand Up @@ -87,11 +88,13 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
Main* blenderdata = maggie1;

char* startscenename = startscene->id.name + 2;
char pathname[FILE_MAXDIR+FILE_MAXFILE];
char pathname[FILE_MAXDIR + FILE_MAXFILE];
char prevPathName[FILE_MAXDIR + FILE_MAXFILE];
std::string exitstring = "";
BlendFileData *bfd = nullptr;

BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
BLI_strncpy(prevPathName, G.main->name, sizeof(prevPathName));

KX_SetOrigPath(std::string(blenderdata->name));

Expand Down Expand Up @@ -149,6 +152,8 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c

if (blenderdata) {
BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
// Change G.main path to ensure loading of data using relative paths.
BLI_strncpy(G.main->name, pathname, sizeof(G.main->name));
}
}
// else forget it, we can't find it
Expand Down Expand Up @@ -238,4 +243,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
PyGILState_Release(gilstate);
#endif

// Restore G.main path.
BLI_strncpy(G.main->name, prevPathName, sizeof(G.main->name));
}

0 comments on commit 2a72166

Please sign in to comment.