Irrlicht 'createDevice' changes current working directory?

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
erwincoumans
Posts: 46
Joined: Tue Oct 02, 2007 6:46 am
Contact:

Irrlicht 'createDevice' changes current working directory?

Post by erwincoumans »

When trying to open a file using fopen, in the current working directory from the console, it can't find the file unless the fopen happens before the Irrlicht 'createDevice' call. (Irrlicht 1.5.1)

Is this change in current working directory intended?
Thanks,
Erwin
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

As said on irc this shouldn't happen. I'll look into it though, moving to bug reports :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I haven't tested this, but it would be nice if you had a testcase to verify this. The following should work on most systems.

Code: Select all

#include <irrlicht.h>
#include <string.h> // for strcmp()
#include <assert.h> // for assert()

#if defined (_IRR_WINDOWS_API_)
#  include <direct.h> // for _getcwd()
#  define getcwd(x,y) _getcwd(x,y)
#else
#  include <unistd.h> // for getcwd()
#endif

using namespace irr;

int main ()
{
  char buf1 [PATH_MAX + 1];
  getcwd (buf1, sizeof buf1);

  IrrlichtDevice* device = createDevice (video::EDT_NULL);

  char buf2 [PATH_MAX + 1];
  getcwd (buf2, sizeof buf2);

  device->drop();

  assert (!strcmp (buf1, buf2));

  return 0;
}
Of course it would be better if you just pointed out where the working directory was being changed. That way bitplane doesn't have to go hunting for it.

Travis
erwincoumans
Posts: 46
Joined: Tue Oct 02, 2007 6:46 am
Contact:

Post by erwincoumans »

Your code is a reproduction case, just replace the Null device by the OpenGL device on Mac OSX. The working directory is changed right after the 'createDevice ' call.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

So this does not happen with the null driver? That's an interesting point, at least a hint where it might happen. Can you debug into the createDevice call and check if it happens in createWindow or createDriver?
Edit: Seems to happen with every driver:

Code: Select all

                path = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
                chdir([path fileSystemRepresentation]);
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

thought it was just me :) I added a path variable to the App class and change it back as I load items. Interested to see where this is headed.....
Post Reply