I’ve started a Close Combat clone, using the original Close Combat
data and I’ve run into a very strange bug. This code works fine on
Linux, but not on Windows with either Dev-C++ or (I’ve been told)
Visual C++ 6. There is a line offset table in each sprite, which
begins with a blank lines (0xffff), then starts with low-numbered
offsets (5, 12, 22, etc). I can’t explain why after the string of
0xffff words, it starts reading 0x8826. 0x8826 is nowhere in the file,
it wasn’t in memory, it seems it’s coming out of nowhere. Here’s a
snippet of code and a shot of GDB dumping the line offset table after
it’s been “loaded” from the file. Does anyone see anything wrong? Or
is this a bug in SDL?
sc->read16 (a function pointer) calls either SDL_ReadLE16 or
SDL_ReadBE16, which is needed because the data may be big endian.
sp[i].height was loaded correctly.
/* Allocate and read the line offset table */
sp[i].line_offset_table = calloc (2, sp[i].height);
if (sp[i].line_offset_table == NULL) goto cleanup;
for (j = 0; j < sp[i].height; ++j)
sp[i].line_offset_table[j] = sc->read16 (sc->f);
(gdb) x/65h sp[i].line_offset_table
0x3f2708: 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff
0x3f2718: 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff
0x3f2728: 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff 0xffff
0x3f2738: 0xffff 0xffff 0x0000 0x0005 0x0026 0x8826 0x8826 0x8826
0x3f2748: 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826
0x3f2758: 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826
0x3f2768: 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826
0x3f2778: 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826 0x8826
0x3f2788: 0x8826
(gdb)
The full code is here
http://www.closecombat.org/forums/showthread.php?p=51401#post51401 and
I can send you a data file you can test it on if you want to give it a
shot.
(sorrt if this mail comes through twice)