//Offscreen surface locked for image transfer
//ddsd is valid
lPitch = ddsd.lPitch;
buffer = (USHORT *)ddsd.lpSurface;
if(lPitch == (1024 * 2))
memcpy((void *)buffer, (void *)image16, (1024 * 768 * 2));
else
{
for(i = 0; i < 768; i++, buffer += lPitch)
memcpy((void *)buffer, (void *)image16, (1024 * 2));
}
I have isolated the problem and it appears to be the memcpy line. Any ideas why?
Etran1
Edited by - etran1 on January 17, 2001 11:02:55 PM
Edited by - etran1 on January 17, 2001 11:03:57 PM
I was wondering if anybody could look at this and tell me why it crashes everytime it gets the following code.
January 17, 2001 10:10 PM
On you second memcopy, i think you need to use;
memcpy((void *)buffer, (void *)image16, (1024 * 2));
memcpy((void *)buffer, (void *)image16, (1024 * 2));
January 17, 2001 10:13 PM
crap, sorry about that,
HTML took out the stuff i added,
if you dont already have an open brace and then an i, and another closing brace after (void *)image16 and before the ,(1024*2) you should add one.
HTML took out the stuff i added,
if you dont already have an open brace and then an i, and another closing brace after (void *)image16 and before the ,(1024*2) you should add one.
January 17, 2001 10:13 PM
crap, sorry about that,
HTML took out the stuff i added,
if you dont already have an open square braket and then an i, and another closing square bracket after (void *)image16 and before the ,(1024*2) you should add one.
HTML took out the stuff i added,
if you dont already have an open square braket and then an i, and another closing square bracket after (void *)image16 and before the ,(1024*2) you should add one.
January 17, 2001 10:14 PM
read the last one i poasted, i messed up the first 2, sorry about that.
ok. well there could be a few things wrong. i suggest doing a debug and record the values of "ddsd.lPitch" and ensure that "image16" and "buffer" are valid pointers. secondly the second "memcpy" is definitely not going to work. there are two problems. i am assuming you declared the pointer "buffer" as a
"unsigned short *". now the problem with that is on the second "memcpy", when you add the pitch you are actually adding double the pitch because the compiler takes into account the pointer''s type size. this is most likely causing the program to crash because after all the additions you eventually overrun into VRAM or other RAM which does not belong to the locked memory.
hope that helps you understand the pointer math a little. now the second problem is on the second "memcpy" again. after the "memcpy" the "image16" memory offset is never updated. so you are copying the first row of the image 768 times. heres some updated code.
hope this helps.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
"unsigned short *". now the problem with that is on the second "memcpy", when you add the pitch you are actually adding double the pitch because the compiler takes into account the pointer''s type size. this is most likely causing the program to crash because after all the additions you eventually overrun into VRAM or other RAM which does not belong to the locked memory.
unsigned char *c = (unsigned char *)0xa0000;unsigned short *s = (unsigned short *)0xa0000;unsigned long *l = (unsigned long *)0xa0000;c += 1; // c = 0xa0001; // sizeof(unsigned char) == 1;s += 1; // s = 0xa0002; // sizeof(unsigned short) == 2;l += 1; // l = 0xa0004; // sizeof(unsigned long) == 4;/* reset the pointer values. */c = (unsigned char *)0xa0000;s = (unsigned short *)0xa0000;l = (unsigned long *)0xa0000;c += 2; // c = 0xa0002;s += 2; // s = 0xa0004;l += 2; // l = 0xa0008;
hope that helps you understand the pointer math a little. now the second problem is on the second "memcpy" again. after the "memcpy" the "image16" memory offset is never updated. so you are copying the first row of the image 768 times. heres some updated code.
long lPitch = ddsd.lPitch;int i;char *buffer = ddsd.lpSurface;if (lPitch == (1024 * 2)) { /* assumption: frame buffer 2048-byte aligned. */ memcpy((void *)buffer, (void *)image16, (1024 * 768 * 2));}else { /* assumption: frame buffer not 2048-byte aligned. */ for (i = 0; i < 768; i++) { memcpy((void *)buffer, (void *)image16, (1024 * 2)); buffer += lPitch; // update the dst. offset. image16 += (1024 * 2); // update the src. offset. }}
hope this helps.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement