- Online Community Forums » Programming Questions » Crash when trying to chance working directory

Credits go to ph03nix for helping out!
This thread is locked; no one can reply to it. rss feed Print
Crash when trying to chance working directory
Hrod Ruck
Member #15,433
December 2013

When I try to change directories to load an image with the following code:
ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
const char * pathstr = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);
if (!al_change_directory(pathstr))
fprintf(stderr, "Erro na mudanca de diretorio.\n");
return -1;
the program simply crashes. It's really weird, since I got the code from older posts so it's supposed to be working.
Also, when I type printf("%s\n", al_get_current_directory); it just prints garbage.

Member #10,584
January 2009

printf("%s\n", al_get_current_directory);
Is this a copy-paste error?
Should be
printf("%s\n", al_get_current_directory());

edit: the above code causes a memory leak. So for proper practice...

char *directory = al_get_current_directory();
// use variable
al_free(directory); // clean up

Hrod Ruck
Member #15,433
December 2013

No, it was actually an error. Now it prints the directory where my source is. THank you! However, I've still got two problems: there is an image there that doesn't load AND my program crashes when I try to get my current directory.

Member #15,028
April 2013

do you call al_init before al_get_current_directory?

Hrod Ruck
Member #15,433
December 2013

Yes, that was the case. Thank you.

Go to: