Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Physfs problem

This thread is locked; no one can reply to it. rss feed Print
Physfs problem
xtheunknown0
Member #13,772
November 2011

Hello,

I've got a 'small' problem with trying to load an image file using physfs. Here's part of a modified ex_physfs.c:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_primitives.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_physfs.h> 6#include <physfs.h> 7#include <allegro5/allegro_font.h> 8#include <allegro5/allegro_ttf.h> 9 10int main(int argc, const char *argv[]) 11{ 12 ALLEGRO_DISPLAY *display; 13 ALLEGRO_BITMAP *bmp; 14 ALLEGRO_FS_ENTRY *entry; 15 int i; 16 17 if (!al_init()) 18 return 1; 19 al_init_primitives_addon(); 20 al_init_font_addon(); 21 al_init_ttf_addon(); 22 23 display = al_create_display(640, 480); 24 if (!display) { 25 return 1; 26 } 27 28 al_init_image_addon(); 29 30 ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); 31 32 al_append_path_component(path, "resources"); 33 al_change_directory(al_path_cstr(path, '/')); // change the working directory 34 ALLEGRO_FONT *font = al_load_ttf_font("DejaVuSans.ttf", 12, 0); 35 if (!font) { 36 al_draw_textf(font, al_map_rgb(255, 255, 255), 50, 1, 0, "Error loading font.\n"); 37 al_rest(4.0); 38 return 1; 39 } 40 al_destroy_path(path); 41 42 43 /* Set up PhysicsFS. */ 44 if (!PHYSFS_init(argv[0])) { 45 al_draw_textf(font, al_map_rgb(255, 255, 255), 50, 1, 0, "Error initialising physicsfs"); 46 al_rest(4.0); 47 return 1; 48 } 49 50 if (!PHYSFS_addToSearchPath("data/ex_physfs.zip", 1)) { 51 al_draw_textf(font, al_map_rgb(255, 255, 255), 50, 50, 0, "Error adding to search path."); 52 al_flip_display(); 53 al_rest(4.0); 54 return 1; 55 } 56 57 return 0; 58}

Why can't A5 find ex_physfs.zip even though it's the data/ is in the same directory as the executable produced?

TIA,
xtheunknown0

Matthew Leverton
Supreme Loser
January 1999
avatar

You've changed into the resources directory, so it's probably looking in resources/data.

xtheunknown0
Member #13,772
November 2011

Now I've added
al_remove_path_component(path, -1);

before the addToSearchPath call, and it still doesn't work. What could I be missing?

TIA,
xtheunknown0

William Labbett
Member #4,486
March 2004
avatar

if (!PHYSFS_addToSearchPath("data/ex_physfs.zip", 1)) {

Are you supposed to have already set up a search path ? (if so, you haven't).

Edgar Reynaldo
Member #8,592
May 2007
avatar

xtheunknown0
Member #13,772
November 2011

Great.

Now A5 won't load the image file. Here's the rest of the code:

   bmp = al_load_bitmap("02.gif");
   if (bmp) {
      show_image(bmp);
      al_rest(4.0);
      al_destroy_bitmap(bmp);
   }   
   else {
      al_draw_textf(font, al_map_rgb(255, 255, 255), 50, 350, 0, "Error loading gif");
      al_flip_display();
      al_rest(4.0);
   }   

   PHYSFS_deinit();
   al_destroy_path(path);

BTW, addToSearchPath works (no need to create one).
This doesn't seem to be consistent with putting resources in a zip folder. Am I not understanding something?

Edgar Reynaldo
Member #8,592
May 2007
avatar

Go to: