Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Can't load bitmap from a zipfile (PhysFS addon help)

This thread is locked; no one can reply to it. rss feed Print
Can't load bitmap from a zipfile (PhysFS addon help)
Restful Cargo
Member #16,106
October 2015

Hello Allegro fans. Allegro newbie and first time poster (please be gentle). I am having trouble getting al_load_bitmap to work with the PhysFS addon. I am using allegro_monolith-debug-5.1.dll from the allegro-msvc2013-x86-5.1.12.zip with PhysFS 2.0.3 and VS2013. I've searched and read the manual and forums threads but without success.

The program is supposed to load a bitmap from a zip file and display it. The code successfully inits everything. It loads the zip file then calls al_set_physfs_file_interface(). Then it proceeds to check if file dodo.bmp exists (which it does). The program then explodes when calling al_load_bitmap(). Visual Studio debugger complains that an access violation exception happened.

I have no idea what I am doing wrong. :-/ If anyone could help I'd appreciate it.

#SelectExpand
1#include <cstdio> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4#include <allegro5/allegro_physfs.h> 5#include <physfs.h> 6 7int main(int argc, char *argv[]) 8{ 9 ALLEGRO_DISPLAY *display = NULL; 10 ALLEGRO_BITMAP *image; 11 12 al_init(); 13 al_init_image_addon(); 14 15 display = al_create_display(320, 200); 16 al_clear_to_color(al_map_rgb(0, 0, 0)); 17 18 if (PHYSFS_init(argv[0]) != 0) 19 if (PHYSFS_mount("test.zip","/",0)) 20 al_set_physfs_file_interface(); 21 else 22 exit(1); 23 else 24 exit(1); 25 26 if (PHYSFS_exists("dodo.bmp")) 27 { 28 image = al_load_bitmap("dodo.bmp"); // <--- CRASHES HERE 29 30 } else { 31 printf("bmp not found"); 32 exit(1); 33 } 34 35 al_draw_bitmap(image, 0, 0, 0); 36 al_flip_display(); 37 al_rest(5); 38 39 return 0; 40}

RPG Hacker
Member #12,492
January 2011
avatar

This is quite a step in the dark... but does "/dodo.bmp" work?
One guess of mine is that you need to add the mount point to the file name when trying to load a file from it.

Arthur Kalliokoski
Second in Command
February 2005
avatar

I just tried your program on Linux and it worked. Perhaps dodo.bmp is some weird 16 color bitmap that Allegro can't handle? Try loading it without the zipfile stuff.

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Restful Cargo
Member #16,106
October 2015

EDIT: Good to hear it works for someone! I tried it with different files. The 02.bmp from the data folder in allegro, a png file, and a couple other bmp's. They're small images. Nothing huge or special about them. I can load files fine directly from the hard drive but can't get the PHYSFS addon to work properly.

@RPG Hacker: Sorry just tried it. Same results. Thanks anyway. Using the older PHYSFS_addToSearchPath() instead of PHYSFS_mount doesn't make a difference either. I get the same problem with the ex_physfs demo. Maybe it's a problem with my Visual Studio. I don't know.

[SOLUTION]
As suggested in another thread I took a look at the "linker->input->additional dependencies" in my project's properties window. For the program to work physfs.lib has to be declared after allegro_monolith-debug.lib (or whatever you use). At least that fixed it for my case. Thanks RPG Hacker and Arthur Kalliokoski for your attention.

SiegeLord
Member #7,827
October 2006
avatar

I just tried this with my MSVC2013 and it seemed to work fine... I used x86 allegro_monolith-debug.lib too. The change you made doesn't seem to make sense to me, since that dependency should have been already linked in that library...

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: