Problems loading using PHYSFS
Neil Roy

The following code will cause the program to freeze up when it goes to load the logo.png which is contained in 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.

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("./", "/", 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.


Try replacing the PHYSFS_mount() with PHYSFS_addToSearchPath().

Neil Roy

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

PHYSFS_addToSearchPath("./", 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 and fail so... <shrug>


Weird. Does the ex_physfs example work?.

Neil Roy

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.

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("./", 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.


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

Neil Roy

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 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)

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("", 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);


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


EDIT: Debugging shows:

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


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


Neil Roy

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. =/


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

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) ;)

Thread #606505. Printed from