GP2X Portable Paths Question (sdl)


namco

Member
Joined
Mar 22, 2006
Messages
410
Age
41
Location
Manchester, UK
Website
www.stupendous-stuff.com
I want to be able to use 1 set of paths to a folder with the images to load into SDL surfaces via the load bitmap function, however, when I use:

CODE

SDL_Surface *test_expensesList = SDL_LoadBMP("graphics/expenseslist.bmp");



SDL segfaults as I'm not specifying:

CODE

SDL_Surface *test_expensesList = SDL_LoadBMP("/mnt/sd/retest/graphics/expensesList.bmp");



I know I could just do:

CODE

#ifndef WIN32
SDL_Surface *test_expensesList = SDL_LoadBMP("graphics/expenseslist.bmp");

// rest of win32 style code

#endif

#ifndef GP2X
SDL_Surface *test_expensesList = SDL_LoadBMP("/mnt/sd/retest/graphics/expensesList.bmp");

// rest of gp2x style code

#endif



and this would not compile the currently defined code. But I just want to be able to use a portable path for cross compiling purposes (i.e. windows and gp2x), without having to write out more code. How do I achieve this?

Thanks.
 
Last edited by a moderator:
The path relativity should not cause a segfault. I've used relative paths and never had a problem.

I do notice that you have expensesList.bmp and expenseslist.bmp in the above example...

Could case sensitivity be your problem?
 
Last edited by a moderator:
I also notice that you're not using " ./ " so on the GP2X it's looking at the root filesystem instead of the current working directory.
 
Last edited by a moderator:
Er... yes... something's not quite right if you're getting segfault's... you might want to double-check the files are Windows format BMP's, and that the case sensitivity is correct and that you aren't doing anything daft with pointers that might cause things to segfault.

I use IMG_Load, but it's the same principle:

SDL_Surface *loading_screen = IMG_Load("images/loading.png");

works fine for me on PC and GP2X without problems (and in Windows, Linux, etc. on the PC).
 
Last edited by a moderator:
@mindlord

Yes, that got it! :)

@PokeParadox

Sorry, that code is a little outdated as I'd changed the filename to all lower case (i.e. expensesList.bmp becomes expenseslist.bmp), as well as the function params. I originally assumed the problem may be linux not liking the uppercase notation in the filename.

Thanks all!
 
Last edited by a moderator:
Still, if the app segfaults because it can't find a filename, then you need some error detection. Eg, make sure the SDL_Surface is valid before trying to use it.
 
Last edited by a moderator:
Back
Top