Jump to content

[SOLVED] with recent app_path change, engine will fall with multiple file not found.


photo

Recommended Posts

I found this when I try to recompile my web player with new sdk, as you know, the web player is just a dll, so this is the way engine will be loaded with a another dll. engine will fall with these lines:

// create gui
   engine.gui = engine.renders->createGui(GUI_PATH);
   engine.gui->setSize(engine.app->getWidth(),engine.app->getHeight());

   // console gui
   engine.console->setGui(engine.gui,CONSOLE_FONT,CONSOLE_SIZE);

   // create splash
   engine.splash = new Splash(engine.gui);

   // create profiler
   engine.profiler = new Profiler(engine.gui,PROFILER_FONT,PROFILER_SIZE);

 

so the situation is when engine is called from another dll, the current working directory can't be the unigine's bin folder, the current directory will always be the browser's exe directory, so use relative path will not work, and I've found a simple solution for this:

// data directory
   data_path = String::pathname(app_path + ::data_path + ENGINE_DATA);
   Dir::chdir(data_path); // add a chdir after data_path is set

 

add a chdir after the data_path is set, this will make createGui to operate on a correct relative directory to find correct ui files. if there is no chdir, engine can not find any fonts, scripts anything specified with relative directory.

 

and if this is not best option, we can add a getCurrentDir at very first of Engine::init, and chdir to that folder at the end of Engine::init. this will not cause the current directory change while make engine work with correct loading files.

Link to comment

well, this is not a correct solution, after use chdir to data directory, the engine sure can be started without any problem, but during engine startup, the sub-directory inside the data directory will not be scanned to filesystem. so, this will cause another problem, none of world can be loaded because engine can't find any files in core directory.

Link to comment

final solution should be this:

// application path
   if(path != NULL) {
  	 #ifdef _WIN32
  		 app_path = String::replace(path,"\\","/");
  	 #else
  		 app_path = path;
  	 #endif
  	 Dir::chdir(app_path);
   } else {

 

add a chdir after set app_path from existing path argument.. a tiny fix..

Link to comment
×
×
  • Create New...