![]() |
|
al_create_fs_entry not working second time after calling destructor |
awergh
Member #15,474
January 2014
|
Anyway basically what happens is that I have a main menu and I start the game this creates a game object and that creates a graphicSetBundle object which is where I am using al_create_fs_entry then from the ingame menu I quit back to main menu calling the game destructor and any others required. Now the problem is that the second time I run the game it doesn't work. al_fs_entry_exists(gfxsetPath) returns false and most interestingly to me is that gfxsetPath instead of giving the full path D:\blah\graphics\sets it has the value of ../graphics/sets This is what gfxsetsDir is equal to in both cases but it does not appear to work/give the same result the second time and I don't understand why 1
2GraphicSetBundle::GraphicSetBundle(const char *gfxsetsDir)
3{
4 ALLEGRO_FS_ENTRY *gfxsetPath = al_create_fs_entry(gfxsetsDir);
5 std::vector< ALLEGRO_FS_ENTRY *> gfxSetFilePaths;
6 al_open_directory(gfxsetPath);
7 printf("gfxsetpath: %s\n", al_get_fs_entry_name(gfxsetPath));
8 printf("isexist?:%i\n",al_fs_entry_exists(gfxsetPath));
9
10 ALLEGRO_FS_ENTRY *next;
11 do
12 {
13 next = al_read_directory(gfxsetPath);
14 if(next != NULL)
15 {
16 gfxSetFilePaths.push_back(next);
17 }
18 }
19 while(next != NULL);
20 al_close_directory(gfxsetPath);
21
22 for(int i=0; i<gfxSetFilePaths.size(); ++i)
23 {
24 currentPath_ = al_create_path(al_get_fs_entry_name(gfxSetFilePaths[i]));
25 bundle_.insert( std::make_pair<std::string, GraphicSet*>(al_get_path_basename(currentPath_), new GraphicSet(currentPath_)) );
26 }
27
28
29 for(int i=0; i<gfxSetFilePaths.size();++i)
30 {
31 al_destroy_fs_entry(gfxSetFilePaths.at(i));
32 }
33 al_destroy_fs_entry(next);
34
35 al_close_directory(gfxsetPath);
36 al_destroy_fs_entry(gfxsetPath);
37
38}
This is being compiled on Windows 8.1 x64 with Visual Studio 2010 not that it should matter. Hopefully that is enough code because there is a fair bit of code if the problem is elsewhere and it may not necessarily be particularly tidy code. I can say everything worked (apart from the memory leaks) as it should before I started loading graphics with physfs. (my hardcoded paths and global variables were annoying me) Edit: it would appear its not the fact that I am deleting my GraphicSetBundle or the Game object that it is created in is the problem. If I create multiple GraphicSetBundles than only the first one will work even if the intended directory is different. Edit Again: Problem Solved ! |
|