Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Does PhysFS work for you with Allegro 5.2.2?

Credits go to Eric Johnson and Todd Cope for helping out!
This thread is locked; no one can reply to it. rss feed Print
Does PhysFS work for you with Allegro 5.2.2?
Edgar Reynaldo
Member #8,592
May 2007
avatar

Hi everybody,

I made some binaries and turns out Neil Roy's Deluxe Pacman 2 game no longer correctly loads ttf files from within a .zip physfs file archive. See thread here. Also, in my distribution, ex_physfs fails to work and quits silently, as it doesn't load 02.bmp from the zip file correctly, even though the zip file is present.

My question, do the other builds of allegro suffer this same difficulty? I built Allegro 5.2.3 from GIT shortly after 5.2.2 was released, so if anyone else using 5.2.2 has this same problem or if it works for them, please let me know.

I built Allegro 5.2.3 from GIT with PhysFS 2.0.3, FreeType2.7.1, LibPNG1.6.28, and ZLib 1.2.11.

Does ex_physfs work for you in your build of allegro? Please tell me if it does.

Thanks, Edgar

Todd Cope
Member #998
November 2000
avatar

It was working here, then I updated all of the dependencies (FreeType, libpng, and zlib) and it no longer works. I modified the example program and saw that it is seeing the structure of the ZIP file, it just can't load the bitmap.

Append: I modified the example to open 02.bmp with al_fopen() and dump the contents and they appear correct. Not sure why al_load_bitmap() can't load it.

Append 2: al_fseek() is failing inside the BMP loader.

Append 3: It works fine when using the zlib provided by Mac OS X.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Todd Cope
Member #998
November 2000
avatar

No, I think I was actually originally using the built-in zlib. I tried installing the old version I had (1.2.8), but it still didn't work. I think I only had that version because I needed it for Android.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Can anyone with windows or other OS'es test out ex_physfs for me? I need to know if the problem is with PhysFS or with Allegro and from when.

Apparently the last time it worked was with Allegro 5.2.1.1 and with FreeType2.6.5 and PhysFS 2.0.3, so PhysFS was the same and it worked. I tried ex_physfs (5.2.1.1) with ex_physfs.zip from 5.2 and it still worked, so the zip file is fine.

{"name":"610860","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/4\/54d2acf8320d0693dd71dd9e166d20e7.png","w":845,"h":326,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/4\/54d2acf8320d0693dd71dd9e166d20e7"}610860

It has to be something to do with allegro and the physfs addon. FreeType wouldn't matter when loading a .bmp and the zip file and physfs are both fine. But the version of zlib I used in 5.2.1.1 was 1.2.8 and the version of zlib I used in 5.2.3 was 1.2.11. It may be a problem with zlib, but if it's not :

Should I file a bug report on github? Send an email to the mailing list? What is the preferred way of reporting things these days?

Can I look up by commits on github or something? Or find all commits that have to do with a certain file?

Eric Johnson
Member #14,841
January 2013
avatar

Can I look up by commits on github or something? Or find all commits that have to do with a certain file?

You can see all of the commits made to a certain file by clicking on the file on GitHub and then clicking on the "Blame" or "History" buttons to the top right of the page.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Todd, I believe this is where you found it was failing before.

A5.2.3GIT said:

addons/image/bmp.c#SelectExpand
1318 /* Skip to the pixel data only if it's outside of the image metadata */ 1319 if (file_start + (int64_t)fileheader.bfOffBits > al_ftell(f)) { 1320 if (!al_fseek(f, file_start + fileheader.bfOffBits, ALLEGRO_SEEK_SET)) { 1321 ALLEGRO_ERROR("Seek error\n"); 1322 return NULL; 1323 } 1324 } 1325 1326 bmp = al_create_bitmap(infoheader.biWidth, abs((int)infoheader.biHeight));

It fails on line 1320 of bmp.c in the call to al_fseek. I'm trying to step further into the code as we speak. It's failing inside f->vtable->fi_fseek which is file_phys_seek.

Todd Cope
Member #998
November 2000
avatar

Yeah, that's exactly where I wound up. The PhysFS call is failing (returns a fail code). I'm not familiar with zlib so I didn't keep going.

Edgar Reynaldo
Member #8,592
May 2007
avatar

EDIT

This is from a known physfs bug in v. 2.0.3. A copy of the patch from that thread is attached here :
https://www.allegro.cc/files/attachment/610879

Original Message

Todd, I believe this is where you found it was failing before.

A5.2.3GIT said:

addons/image/bmp.c#SelectExpand
1318 /* Skip to the pixel data only if it's outside of the image metadata */ 1319 if (file_start + (int64_t)fileheader.bfOffBits > al_ftell(f)) { 1320 if (!al_fseek(f, file_start + fileheader.bfOffBits, ALLEGRO_SEEK_SET)) { 1321 ALLEGRO_ERROR("Seek error\n"); 1322 return NULL; 1323 } 1324 } 1325 1326 bmp = al_create_bitmap(infoheader.biWidth, abs((int)infoheader.biHeight));

It fails on line 1320 of bmp.c in the call to al_fseek. I'm trying to step further into the code as we speak. It's failing inside f->vtable->fi_fseek which is file_phys_seek.

EDIT
It's failing inside ZIP_seek in a call to ZIP_read.

Here's the debug output :

#SelectExpand
1 2c:\LIBS5303Distro\Allegro522_MinGW5303\bin\examples>gdb ex_physfs.exe 3GNU gdb (GDB) 7.6.1 4 5Breakpoint 2, main (argc=1, argv=0x13e8130) at C:\LIBS5303Build\allegro5\examples\ex_physfs.c:165 6165 bmp = al_load_bitmap("02.bmp"); 7(gdb) c 8Continuing. 9 10Breakpoint 4, file_phys_seek (f=0x13eb030, offset=0, whence=0) 11 at C:\LIBS5303Build\allegro5\addons\physfs\a5_physfs.c:185 12185 ALLEGRO_FILE_PHYSFS *fp = cast_stream(f); 13(gdb) bt 14#0 file_phys_seek (f=0x13eb030, offset=0, whence=0) at C:\LIBS5303Build\allegro5\addons\physfs\a5_physfs.c:185 15#1 0x677a74b1 in al_fseek (f=0x13eb030, offset=0, whence=0) at C:\LIBS5303Build\allegro5\src\file.c:175 16#2 0x678716e6 in _al_load_bmp_f (f=0x13eb030, flags=0) at C:\LIBS5303Build\allegro5\addons\image\bmp.c:1303 17#3 0x678726db in _al_load_bmp (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp", flags=0) 18 at C:\LIBS5303Build\allegro5\addons\image\bmp.c:1596 19#4 0x67783ffd in al_load_bitmap_flags (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp", flags=0) 20 at C:\LIBS5303Build\allegro5\src\bitmap_io.c:209 21#5 0x67783f39 in al_load_bitmap (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp") 22 at C:\LIBS5303Build\allegro5\src\bitmap_io.c:184 23#6 0x00401a8c in main (argc=1, argv=0x13e8130) at C:\LIBS5303Build\allegro5\examples\ex_physfs.c:165 24(gdb) continue 25Continuing. 26[New Thread 12396.0x3238] 27[New Thread 12396.0x760] 28 29Breakpoint 3, _al_load_bmp_f (f=0x13eb030, flags=0) at C:\LIBS5303Build\allegro5\addons\image\bmp.c:1320 301320 if (!al_fseek(f, file_start + fileheader.bfOffBits, ALLEGRO_SEEK_SET)) { 31(gdb) step 32al_fseek (f=0x13eb030, offset=118, whence=0) at C:\LIBS5303Build\allegro5\src\file.c:160 33160 ASSERT(f); 34(gdb) l 35155 36156 /* Function: al_fseek 37157 */ 38158 bool al_fseek(ALLEGRO_FILE *f, int64_t offset, int whence) 39159 { 40160 ASSERT(f); 41161 /* offset can be negative */ 42162 ASSERT( 43163 whence == ALLEGRO_SEEK_SET || 44164 whence == ALLEGRO_SEEK_CUR || 45(gdb) n 46162 ASSERT( 47(gdb) 48168 if (f->ungetc_len) { 49(gdb) 50175 return f->vtable->fi_fseek(f, offset, whence); 51(gdb) step 52 53Breakpoint 4, file_phys_seek (f=0x13eb030, offset=118, whence=0) 54 at C:\LIBS5303Build\allegro5\addons\physfs\a5_physfs.c:185 55185 ALLEGRO_FILE_PHYSFS *fp = cast_stream(f); 56(gdb)l 57214 if (!PHYSFS_seek(fp->phys, base + offset)) { 58215 phys_set_errno(fp); 59216 return false; 60217 } 61 62... 63 64(gdb) frame 0 65#0 ZIP_seek (opaque=0x13ea4e0, offset=118) at C:\LIBS5303Build\physfs-2.0.3\archivers\zip.c:297 66(gdb) n 67298 ZIPentry *entry = finfo->entry; 68(gdb) 69299 void *in = finfo->handle; 70(gdb) 71301 BAIL_IF_MACRO(offset > entry->uncompressed_size, ERR_PAST_EOF, 0); 72(gdb) 73303 if (entry->compression_method == COMPMETH_NONE) 74(gdb) 75318 if (offset < finfo->uncompressed_position) 76(gdb) 77334 while (finfo->uncompressed_position != offset) 78(gdb) 79339 maxread = (PHYSFS_uint32) (offset - finfo->uncompressed_position); 80(gdb) 81340 if (maxread > sizeof (buf)) 82(gdb) 83343 if (ZIP_read(finfo, buf, maxread, 1) != 1) 84(gdb) 85344 return(0); 86(gdb) 87349 } /* ZIP_seek */ 88(gdb) 89PHYSFS_seek (handle=0x2c50798, pos=118) at C:\LIBS5303Build\physfs-2.0.3\physfs.c:2067 902067 } /* PHYSFS_seek */ 91(gdb) 92file_phys_seek (f=0x13eb030, offset=118, whence=0) at C:\LIBS5303Build\allegro5\addons\physfs\a5_physfs.c:215 93215 phys_set_errno(fp); 94(gdb) p fp 95$13 = (ALLEGRO_FILE_PHYSFS *) 0x13ea548 96(gdb) l 97210 al_set_errno(EINVAL); 98211 return false; 99212 } 100213 101214 if (!PHYSFS_seek(fp->phys, base + offset)) { 102215 phys_set_errno(fp); 103216 return false; 104217 } 105218 106219 return true; 107(gdb) frame 0 108#0 file_phys_seek (f=0x13eb030, offset=118, whence=0) at C:\LIBS5303Build\allegro5\addons\physfs\a5_physfs.c:215 109215 phys_set_errno(fp); 110(gdb) l 111210 al_set_errno(EINVAL); 112211 return false; 113212 } 114213 115214 if (!PHYSFS_seek(fp->phys, base + offset)) { 116215 phys_set_errno(fp); 117216 return false; 118217 } 119218 120219 return true; 121(gdb) bt 122#0 file_phys_seek (f=0x13eb030, offset=118, whence=0) at C:\LIBS5303Build\allegro5\addons\physfs\a5_physfs.c:215 123#1 0x677a74b1 in al_fseek (f=0x13eb030, offset=118, whence=0) at C:\LIBS5303Build\allegro5\src\file.c:175 124#2 0x67871860 in _al_load_bmp_f (f=0x13eb030, flags=0) at C:\LIBS5303Build\allegro5\addons\image\bmp.c:1320 125#3 0x678726db in _al_load_bmp (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp", flags=0) 126 at C:\LIBS5303Build\allegro5\addons\image\bmp.c:1596 127#4 0x67783ffd in al_load_bitmap_flags (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp", flags=0) 128 at C:\LIBS5303Build\allegro5\src\bitmap_io.c:209 129#5 0x67783f39 in al_load_bitmap (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp") 130 at C:\LIBS5303Build\allegro5\src\bitmap_io.c:184 131#6 0x00401a8c in main (argc=1, argv=0x13e8130) at C:\LIBS5303Build\allegro5\examples\ex_physfs.c:165 132(gdb)

It's failing inside a call to inflate and zlib_err is returning -2 which means #define Z_STREAM_ERROR (-2). That's the best I can make of this.

#SelectExpand
1258 rc = zlib_err(inflate(&finfo->stream, Z_SYNC_FLUSH)); 2(gdb) 3259 retval += (finfo->stream.total_out - before); 4(gdb) 5261 if (rc != Z_OK) 6(gdb) 7262 break; 8(gdb) p rc 9$14 = -2 10(gdb) p Z_OK 11No symbol "Z_OK" in current context. 12(gdb) bt 13#0 ZIP_read (opaque=0x12aa4e0, buf=0x61eaa8, objSize=118, objCount=1) 14 at C:\LIBS5303Build\physfs-2.0.3\archivers\zip.c:262 15#1 0x64a0fe28 in ZIP_seek (opaque=0x12aa4e0, offset=118) at C:\LIBS5303Build\physfs-2.0.3\archivers\zip.c:343 16#2 0x64a0508c in PHYSFS_seek (handle=0x5150798, pos=118) at C:\LIBS5303Build\physfs-2.0.3\physfs.c:2066 17#3 0x67891e7e in file_phys_seek (f=0x12ab030, offset=118, whence=0) 18 at C:\LIBS5303Build\allegro5\addons\physfs\a5_physfs.c:214 19#4 0x677a74b1 in al_fseek (f=0x12ab030, offset=118, whence=0) at C:\LIBS5303Build\allegro5\src\file.c:175 20#5 0x67871860 in _al_load_bmp_f (f=0x12ab030, flags=0) at C:\LIBS5303Build\allegro5\addons\image\bmp.c:1320 21#6 0x678726db in _al_load_bmp (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp", flags=0) 22 at C:\LIBS5303Build\allegro5\addons\image\bmp.c:1596 23#7 0x67783ffd in al_load_bitmap_flags (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp", flags=0) 24 at C:\LIBS5303Build\allegro5\src\bitmap_io.c:209 25#8 0x67783f39 in al_load_bitmap (filename=0x40b1ee <__register_frame_info+4239854> "02.bmp") 26 at C:\LIBS5303Build\allegro5\src\bitmap_io.c:184 27#9 0x00401a8c in main (argc=1, argv=0x12a8130) at C:\LIBS5303Build\allegro5\examples\ex_physfs.c:165 28(gdb) l 29257 30258 rc = zlib_err(inflate(&finfo->stream, Z_SYNC_FLUSH)); 31259 retval += (finfo->stream.total_out - before); 32260 33261 if (rc != Z_OK) 34262 break; 35263 } /* while */ 36264 37265 retval /= objSize; 38266 } /* else */ 39(gdb) p rc 40$15 = -2 41(gdb)

Go to: