Working directory is wrong (MacOSX)

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
BitPuffin
Posts: 8
Joined: Mon Apr 01, 2013 8:25 pm

Working directory is wrong (MacOSX)

Post by BitPuffin »

Hello!

I'm having some trouble with working directories with irrlicht.
For some satanic reason the working directory reported by:

Code: Select all

device->getFileSystem()->getWorkingDirectory();
Is the parent directory. Which would explain why it can't open my mesh at the location data/cube.dae perhaps.
Although for another satanic reason it can't open it if I say project-dir/data/cube.dae either. So that's fun!

So just to be clear:

Code: Select all

 
% pwd
/Users/isak/src/cpp/broccoli-boy
% ./who-will-laugh-at-broccoli-boy
 
Gives the output:

Code: Select all

 
Starting game, prepare to poop pants
Ran with command: ./who-will-laugh-at-broccoli-boy
Irrlicht Engine version 1.8.1
Darwin Kernel Version 13.1.0: Wed Apr  2 23:52:02 PDT 2014; root:xnu-2422.92.1~2/RELEASE_X86_64
Using renderer: OpenGL 2.1
NVIDIA GeForce GT 750M OpenGL Engine: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
GLSL version: 1.2
;;;; WORKING DIRECTORY: /Users/isak/src/cpp
Could not load mesh, because file could not be opened: : broccoli-boy/data/cube.dae
 
Source code:

Code: Select all

 
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include "irrlicht/irrlicht.h"
//#include "allegro5/allegro.h"
#include "newton/Newton.h"
 
#define WINDOW_WIDTH 1920
#define WINDOW_HEIGHT 1080
 
using namespace std;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
 
 
int main(int argc, char **argv) {
  cout << "Starting game, prepare to poop pants" << endl;
  cout << "Ran with command: " << argv[0] << endl;
 
  IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<u32>(WINDOW_WIDTH, WINDOW_HEIGHT), 32, false, true, true);
  device->setWindowCaption(L"Who will laugh at broccoli boy?");
 
  cout << ";;;; WORKING DIRECTORY: "  << device->getFileSystem()->getWorkingDirectory().c_str() << endl;
 
  if(!device) {
    return EXIT_FAILURE;
  }
 
  //  if(!al_init()) {
  //  return EXIT_FAILURE;
  // }
 
  IVideoDriver *video_driver = device->getVideoDriver();
  ISceneManager *scene_manager = device->getSceneManager();
 
  IMesh *cube = scene_manager->getMesh("broccoli-boy/data/cube.dae");
  if (!cube) {
    //  al_uninstall_system();
    device->drop();
    return EXIT_FAILURE;
  }
 
  IMeshSceneNode *cube_node = scene_manager->addMeshSceneNode(cube);
  if (cube_node) {
    cout << "Halelujah" << endl;
    cube_node->setMaterialFlag(EMF_LIGHTING, false);
  }
 
  scene_manager->addCameraSceneNode(0, vector3df(0, 0, -40), vector3df(0, 0, 0));
  
  while(device->run()) {
    video_driver->beginScene(true, true, SColor(100, 0, 0, 0));
 
    //scene_manager->drawAll();
 
    video_driver->endScene();
  }
 
  //al_uninstall_system();
  device->drop();
 
  return 0;
}
 
Help would be very appreciated, even more so fast response since I'm right in the middle of a game jam :/ But that's not really always doable.
Like the topic suggests this is on mac os x.

When I've used other libraries ilke Allegro I have been able to reference paths like data/bla.png without any problems so it's not a general Mac OS X thing. But an irrlicht on Mac OS X thing. :(
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Working directory is wrong (MacOSX)

Post by Nadro »

Yes, it should be changed. Currently I'm updating ogl-es branch and at next I'll change this.
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
BitPuffin
Posts: 8
Joined: Mon Apr 01, 2013 8:25 pm

Re: Working directory is wrong (MacOSX)

Post by BitPuffin »

Do you have any suggestion for a workaround in the mean time?
BitPuffin
Posts: 8
Joined: Mon Apr 01, 2013 8:25 pm

Re: Working directory is wrong (MacOSX)

Post by BitPuffin »

Okay so what I did is horrible and awful.

Basically path data_path;
data_path.append(blabla->getWorkingDirectory());
data_path.append("/broccoli-boy/data/");

._.

Oh well haha.
Nadro
Posts: 1648
Joined: Sun Feb 19, 2006 9:08 am
Location: Warsaw, Poland

Re: Working directory is wrong (MacOSX)

Post by Nadro »

As workaround you can also use something like this:

Code: Select all

NSAutoreleasePool* tPool = [[NSAutoreleasePool alloc] init];
NSBundle* tBundle = [NSBundle mainBundle];
NSString* tPath = [tBundle bundlePath];
std::string tPathSTR = [tPath cStringUsingEncoding:NSASCIIStringEncoding];
tPathSTR += "/Contents/Resources";
[tPool release];    
Device->getFileSystem()->changeWorkingDirectoryTo(tPathSTR.c_str());
Library helping with network requests, tasks management, logger etc in desktop and mobile apps: https://github.com/GrupaPracuj/hermes
BitPuffin
Posts: 8
Joined: Mon Apr 01, 2013 8:25 pm

Re: Working directory is wrong (MacOSX)

Post by BitPuffin »

Oddly enough putting the exectubable in a Whatevername.app/Contents/MacOSX directory also changes the behaviour of this issue. Which is a little bit mind blowing.
Post Reply