problem with working directory [solved]

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
wiznoe
Posts: 8
Joined: Wed Jun 18, 2008 4:40 am
Location: Jogja, Indonesia

problem with working directory [solved]

Post by wiznoe »

Hi all,
i want to load a scene from directory, but cannot, in the console written like this :
could not load mesh, because file could cot be opened: meshes/tipe21/house21.irr
could not open file of texture: material/wood.bmp
...
etc

i think my problem on the working directory, like in the irredit, that the working directory can be setting,
than how to change my working directory on my code?
plz anybody help me, sorry for my bad english.
thanks
:)
Last edited by wiznoe on Mon Aug 18, 2008 4:52 am, edited 2 times in total.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Just set your working directory in IrrEdit to the directory of your Irrlicht app and have all your assets local to your irrlicht app.
Image Image Image
NemoStein
Posts: 17
Joined: Mon Aug 11, 2008 12:04 am

Post by NemoStein »

Go to "Tools -> Options -> Working Directory" and set the path to the folder that your .exe is...
Close your IrrEdit and open it again...

Now should work... ;D
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

And you'll have to re-save your .irr file to update the file paths in it ;)
Image Image Image
wiznoe
Posts: 8
Joined: Wed Jun 18, 2008 4:40 am
Location: Jogja, Indonesia

Post by wiznoe »

Yeah, i ever do that, i know to set working direktory in irredit,
but when i open scene pass openfile dialog box, all the mesh in that scene (irr file) cannot load, any idea?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Is this in IrrEdit it won't load? Or Irrlicht?

Are the meshes actually in the correct location? And what is house21.irr? Is that actually an irr file? Keeping in mind that irr is a scene format not a model format...
Image Image Image
pera
Posts: 460
Joined: Wed May 14, 2008 1:05 pm
Location: Novi Sad, Serbia
Contact:

Post by pera »

after using FileOpenDialog in Irrlicht, working dir remains where irr scene file was, so you have to write:

filesystem->changeWorkingDirectoryTo("myworkingdir");

to change it back to where your root is.

filesystem is of type IFileSystem* and you can get it with device->getFileSystem();
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah before you open the file dialog, cache the current working directory and then once the file dialog is closed reset the working directory to the one you cached.
Image Image Image
wiznoe
Posts: 8
Joined: Wed Jun 18, 2008 4:40 am
Location: Jogja, Indonesia

Post by wiznoe »

Thanks a lot, i will try it.
:)
wiznoe
Posts: 8
Joined: Wed Jun 18, 2008 4:40 am
Location: Jogja, Indonesia

Post by wiznoe »

Hi JP & Pera,
sorry, maybe i'm stupid, but i can't change the working directory in my irrlicht app.
This is my code :

Code: Select all

		case EGET_FILE_SELECTED:
				{
					IFileSystem * m_FS = device->getFileSystem();
					printf("\n#dir1:: %s",stringc(m_FS->getWorkingDirectory()).c_str());
					IGUIFileOpenDialog* dialog =
						(IGUIFileOpenDialog*)event.GUIEvent.Caller;
					
					smgr->clear();
					
					loadRumah(smgr,stringc(dialog->getFileName()).c_str());
					stringc m_WorkingDirectory = "C:\SPPK Rumah V1.4\sppk\sppk.";
					m_FS->changeWorkingDirectoryTo(m_WorkingDirectory.c_str());
					printf("\ndir now in= %s",stringc(m_FS->getWorkingDirectory()).c_str());
				}
this code is path of IEventReceiver, that the file of scene is open from FileOpenDialog. I confused that where the code of changeWorkingDirectory have placed.
Please help me, maybe all of u have a sample code like my mean..
Sorry for my english, i wish u know.
:oops:
pera
Posts: 460
Joined: Wed May 14, 2008 1:05 pm
Location: Novi Sad, Serbia
Contact:

Post by pera »

you should post what is the problem - is there compiler error, what dir have you end up in?

I see two potential problems,

1 problem is in line
stringc m_WorkingDirectory = "C:\SPPK Rumah V1.4\sppk\sppk.";
cause escape character \ can act weird in that string. Change it to \\ or /

second, EGET_FILE_SELECTED is event called after you pick your scene! so you are already in the wrong dir (not the root one)
go to the code where you call the FileOpenDialog to appear, there, before calling dialog, store your working dir:

stringc m_WorkingDirectory = m_FS->getWorkingDirectory();

then in eget file selected event write

m_FS->changeWorkingDirectoryTo(m_WorkingDirectory.c_str());

BEFORE loading your scene :)

I had probles with that too ;)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Plus you shouldn't ever set a path like C:/blah/blah because that relies on a specific driver and directory structure which you will not have control over on a user's PC if you decide to release your app so you should only do this if you're using the app only your PC for its entire life, and even then it's bad practice.
Image Image Image
Post Reply