Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problems loading using PHYSFS

This thread is locked; no one can reply to it. rss feed Print
Problems loading using PHYSFS
Neil Roy
Member #2,229
April 2002
avatar

The following code will cause the program to freeze up when it goes to load the logo.png which is contained in data.zip. If I comment out the PHYSFS code and just try and load the logo from the folder rather than the zip, it loads and displays no problem.

#SelectExpand
1#include <physfs.h> 2#include <allegro5/allegro_physfs.h> 3 4. 5. 6. 7. 8 9 if(!PHYSFS_init(argv[0])) return 1; 10 11 if (!PHYSFS_mount("./data.zip", "/", 1)) 12 { 13 const char *text = PHYSFS_getLastError(); 14 error(AT, display, text); 15 exit(1); 16 } 17 al_set_physfs_file_interface(); 18 19 image = al_load_bitmap("logo.png");

Plus I am linking in the relevant allegro and physfs libs. All using CodeBlocks.

I am totally new to Allegro 5 and this library, so not sure what I may be doing wrong.

kenmasters1976
Member #8,794
July 2007

Try replacing the PHYSFS_mount() with PHYSFS_addToSearchPath().

Neil Roy
Member #2,229
April 2002
avatar

Tried that, same difference. Crashes when loading the png.

PHYSFS_addToSearchPath("./data.zip", 1);

Like I said, the images load up and display fine without PHSYFS.

I checked the return of PHSYFS as well to see if it has an error and it passes just fine. I'll have to look up to see if they have a function to display the final PHYSFS path to see if maybe it's somehow getting that wrong, but then if it did, it shouldn't find data.zip and fail so... <shrug>

kenmasters1976
Member #8,794
July 2007

Weird. Does the ex_physfs example work?.

Neil Roy
Member #2,229
April 2002
avatar

Yes, it does. That's what I don't understand.

I cut out everything not related to the problem from my code and recompiled it with the same problem.

Here is the complete program.

#SelectExpand
1#include <zlib.h> 2#include <physfs.h> 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_physfs.h> 6#include "error.h" 7 8 9int main(int argc, char *argv[]) 10{ 11 ALLEGRO_DISPLAY *display; 12 ALLEGRO_BITMAP *image; 13 14 PHYSFS_init(argv[0]); 15 PHYSFS_addToSearchPath("./data.zip", 1); 16 17 al_init(); 18 al_init_image_addon(); 19 al_set_physfs_file_interface(); 20 21 display = al_create_display(800, 600); 22 23 image = al_load_bitmap("logo.png"); 24 if(!image) 25 { 26 error(AT, display, "logo.png not found"); 27 exit(1); 28 } 29 30 al_draw_bitmap(image, 0, 0, 0); 31 al_draw_bitmap(image, 10, 10, 0); 32 33 al_flip_display(); 34 35 al_rest(5); 36 37 return 0; 38}

The PNG I am using is just one I made with the allegro example that outputs a PNG. This code will crash when it goes to load the png in. If you comment out the physfs stuff it runs fine.

I've even tried shifting around where the includes are (before and after allegro includes), you name it.

Compiling produces no errors or warnings... frustrating.

kenmasters1976
Member #8,794
July 2007

What if you call PHYSFS_init() and PHYSFS_addToSearchPath() after you do the Allegro initialization?.

Neil Roy
Member #2,229
April 2002
avatar

Tried that, actually I originally had it after, I put it before after searching for an answer and noticing that someone else had it before.

I added in some more code to check for errors and display the path(s) stored in PhysFS before it loads and it shows data.zip in the path. (I removed the ./ to see if that makes a difference, it doesn't)

(note: I use error() to display a popup message with an OK prompt)

#SelectExpand
1#include <zlib.h> 2#include <physfs.h> 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_physfs.h> 6#include "error.h" 7 8 9int main(int argc, char *argv[]) 10{ 11 ALLEGRO_DISPLAY *display = NULL; 12 ALLEGRO_BITMAP *image; 13 14 al_init(); 15 al_init_image_addon(); 16 17 18 PHYSFS_init(argv[0]); 19 if(!PHYSFS_addToSearchPath("data.zip", 1)) 20 { 21 error(AT, display, "PHSYFS_init() failed"); 22 exit(1); 23 } 24 al_set_physfs_file_interface(); 25 26 display = al_create_display(800, 600); 27 28 char **i; 29 for (i = PHYSFS_getSearchPath(); *i != NULL; i++) 30 error(AT, display, *i); 31 32 33 image = al_load_bitmap("logo.png"); 34 if(!image) 35 { 36 error(AT, display, "logo.png not found"); 37 exit(1); 38 } 39 40 al_draw_bitmap(image, 0, 0, 0); 41 al_draw_bitmap(image, 10, 10, 0); 42 43 al_flip_display(); 44 45 al_rest(5); 46 47 return 0; 48}

for completeness here's the error files

for error.c:

// Allegro 5 error message

#include "error.h"

void error(const char *func, int line, ALLEGRO_DISPLAY *display, const char *message)
{
   char text[256];

   sprintf(text, "%s(%d): %s", func, line, message);
   al_show_native_message_box(display, "Error", NULL, text,
                              NULL, ALLEGRO_MESSAGEBOX_ERROR);
}

for error.h:

#ifndef _al_error_h_
#define _al_error_h_

#include <stdio.h>
#include <allegro5/allegro_native_dialog.h>

// usage: error(AT, display, "your message here");
#define AT __func__,__LINE__
void error(const char *func, int line, ALLEGRO_DISPLAY *display, const char *message);

#endif

and the png I am trying to load. I zip this up with 7zip in a file named data.zip. There's no folders or other stored directory structures in the zip either. ;)

{"name":"603465","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/e\/aebd5268fc35bcc9397342756f942472.png","w":491,"h":127,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/e\/aebd5268fc35bcc9397342756f942472"}603465

EDIT: Debugging shows:

Program received signal SIGSEGV, Segmentation fault.
In ?? () ()
At C:\Users\Neil\Develop\physfs-2.0.2\physfs.c:309

kenmasters1976
Member #8,794
July 2007

That's weird. I compiled your code and it works fine:

{"name":"603466","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/4\/0445092ca1bd840d06f3d6dee5e9a71f.png","w":807,"h":631,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/4\/0445092ca1bd840d06f3d6dee5e9a71f"}603466

Neil Roy
Member #2,229
April 2002
avatar

I'm curious, what did you compile it with, which files did you link it with?

Perhaps I missed something... although I linked all libs... <shrug>

I don't think the fact that you're using Windows XP would make a difference (I'm on Windows 7-64bit).

EDIT: Okay, I solved it.

I removed ALL the libraries I was linking and re-added them in and I think I added in libphysfs.a instead of libphysfs.dll.a by accident. not sure about the difference, I assume one is a statically linked lib. =/

kenmasters1976
Member #8,794
July 2007

Well, I didn't use your error.h and error.c files; instead just replaced all error() calls with printf() but that shouldn't be the problem.

As for linking, I just link with all the Allegro libs (they're all set in an environment variable as a shortcut) and the shared PhysFS 2.0.1 lib, that is -lphysfs.dll using MinGW.

[EDIT:] Glad to see you solved it.

Neil Roy
Member #2,229
April 2002
avatar

Thanks a lot for your assistance anyhow, I really want to get this project off the ground sometime this century. (recreating my Deluxe Pacman game from scratch, only with a new, non-copyrighted name) ;)

Go to: