Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 01-08-2010, 10:57 PM   #1
The Fifth Horseman
FUTURE SCIENCE BASTARD
 
The Fifth Horseman's Avatar


 
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
Default memcpy... Uh, doesn't?

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.
Attached Files
File Type: rar chp_advance(working).rar (5.5 KB, 2 views)
File Type: rar chp_advance(not working).rar (6.1 KB, 2 views)
__________________

"God. Can't you people see I'm trying to commit a crime against science and nature here?"
-- Reed Richards
The Fifth Horseman is offline                         Send a private message to The Fifth Horseman
Reply With Quote
Old 02-08-2010, 09:33 PM   #2
Kippesoep
Forum hobbit
 
Kippesoep's Avatar


 
Join Date: Nov 2007
Location: Etten, Netherlands
Posts: 42
Default

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);
}
Kippesoep is offline                         Send a private message to Kippesoep
Reply With Quote
Old 02-08-2010, 11:11 PM   #3
The Fifth Horseman
FUTURE SCIENCE BASTARD
 
The Fifth Horseman's Avatar


 
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
Default

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

"God. Can't you people see I'm trying to commit a crime against science and nature here?"
-- Reed Richards
The Fifth Horseman is offline                         Send a private message to The Fifth Horseman
Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 07:26 PM (GMT)

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