Forums

Forums (http://www.abandonia.com/vbullet/index.php)
-   Programming (http://www.abandonia.com/vbullet/forumdisplay.php?f=25)
-   -   memcpy... Uh, doesn't? (http://www.abandonia.com/vbullet/showthread.php?t=25401)

The Fifth Horseman 01-08-2010 10:57 PM

memcpy... Uh, doesn't?
 
2 Attachment(s)
This is an old project I've decided to complete recently(mostly out of sheer boredom) - a program to extract sprites from Space Hulk and convert them to PCX format.

The program is workin (just compile the version labelled as "working", drop it into the game's CHP_DIR subdirectory and run it), but I'm running into some trouble when I'm trying to modify it to reduce the size of the palette declaration.

Instead of initializing the entire set of palettes on start, I'm trying to assemble five of the palettes from two parts each (because almost half of the palette length from the beginning is common for all five), and then add three entire palettes from another table.

The problem is that while the former part works flawlessly, the latter doesn't. The files using those last three palettes instead have the relevant section filled either with zeroes or garbage.

Frankly, at this point I'm just curious why the test version of the program fails in this fashion - it's just something to tinker around with, since the functional version of the program already performs fine in its' task.

I've attached the source code along with the includes.

Kippesoep 02-08-2010 09:33 PM

It took me a while to find the problem as the code seems messy to me, but the actual root cause is quite simple:

Code:

//This is in the header
char pal57_init[3][769]={ ... }
//that's pal57_init[0], pal57_init[1] and pal57_init[2]

//This makes use of it
for (int i=5; i<8; i++)
{
        memcpy(pcx_palette[i], pal57_init[i], 769);
}
//that's pal57_init[5], pal57_init[6] and pal57_init[7]
//which haven't been defined. The following would work:

for (int i=5; i<8; i++)
{
        memcpy(pcx_palette[i], pal57_init[i-5], 769);
}


The Fifth Horseman 02-08-2010 11:11 PM

*facepalm*
You're right. This solved the problem, thanks! :)


The current time is 10:35 AM (GMT)

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.