Background: I've been learning to use the engine so I can build a simulation for a Professor at my university. So far I've been toying with the tutorials and have been mixing code to get the desired results. I had been testing on windows and recently moved to Linux, and then moved from using code::blocks to using commandline for compiling and running
The code currently loads and displays a skybox(using the example textures at this time), a model I've created in blender, and a terrain(yet again example files).
Problem: When I run the program from code blocks it runs fine. How ever when i run the program from the command line it fails to load the needed texture and terrain map. I first thought it might be a permission issue, so i used chmod to change the permissions of the files.
I found that if I change to directory with the resources and run the program there are no errors, but if i run the program from any other directory it fails. As a note I am not moving the location of the program for any of this. What I can gather is the program is ignoring where I'm telling it to look in the calls to "getTexture()" and "addTerrainSceneNode()"
Additional Notes: I'm trying to use the engine with ROS since my computer can not run the 3D rendering package that ROS recommends
Program fails to load Textures during runtime[Linux]
Re: Program fails to load Textures during runtime[Linux]
Sound like you have different working folders. In c:b it's called execution working dir (somewhere in properties - build targets) and all relative paths start from there on.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: Program fails to load Textures during runtime[Linux]
Alright, so how do I change working directories if I'm not using code::blocks?
Edit: Besides using cd, I need to run the program from different directories than just the one with the resource files
Edit: Besides using cd, I need to run the program from different directories than just the one with the resource files
Re: Program fails to load Textures during runtime[Linux]
Irrlicht has the functions IFileSystem::getWorkingDirectory (to find out which one you have, I think it works like getcwd) and IFileSystem::changeWorkingDirectoryTo.
But this is generally a little tricky and the amount of work needed depends on what you really need. Just for developing I usually set the execution working dir in c::b to the path where my binary is and make all paths relative to that. This works mostly well. Except when it doesn't (for example when called from subfolders or filebrowsers or in the debugger you can have the working-directory set to something else).
I must admit I don't really know what the usual solution for media-paths is on Linux. On Windows you usually set the media-path on installation and just write it into a registry-key from where you read it then in the application.
It is possible to figure out the path of your binary by a combination of getting the current working directory and checking the first parameter in your main function. Like that (not using the Irrlicht functions here as I also use this outside of my Irrlicht apps):
Running this in different situations you get results like that: http://ideone.com/yxbF6D
(binpath is the name of the binary, first line is always how I called the code above and then it prints the cwd and the first argument in argv).
If your media-folder is relative to your binary you can figure out the rest.
There might be other solutions by using some shell-scripts to call your real binary (which is often needed anyway), but I'm not so familiar with all that shell magic to help you much there.
But this is generally a little tricky and the amount of work needed depends on what you really need. Just for developing I usually set the execution working dir in c::b to the path where my binary is and make all paths relative to that. This works mostly well. Except when it doesn't (for example when called from subfolders or filebrowsers or in the debugger you can have the working-directory set to something else).
I must admit I don't really know what the usual solution for media-paths is on Linux. On Windows you usually set the media-path on installation and just write it into a registry-key from where you read it then in the application.
It is possible to figure out the path of your binary by a combination of getting the current working directory and checking the first parameter in your main function. Like that (not using the Irrlicht functions here as I also use this outside of my Irrlicht apps):
Code: Select all
#include <cstdio>
#include <unistd.h>
#ifndef MAXPATHLEN
#define MAXPATHLEN 1024
#endif // MAXPATHLEN
int main (int argc, char *argv[])
{
FILE * f = fopen("binpath.txt", "a");
char cwd[MAXPATHLEN];
getcwd(cwd, MAXPATHLEN);
printf("cwd: %s\n", cwd);
fprintf(f, "cwd: %s\n", cwd);
for (int i = 0; i < argc; i++)
{
printf("argv[%d]: %s\n", i, argv[i]);
fprintf(f, "argv[%d]: %s\n", i, argv[i]);
}
fclose(f);
return 0;
}
(binpath is the name of the binary, first line is always how I called the code above and then it prints the cwd and the first argument in argv).
If your media-folder is relative to your binary you can figure out the rest.
There might be other solutions by using some shell-scripts to call your real binary (which is often needed anyway), but I'm not so familiar with all that shell magic to help you much there.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm