hr=lpddbackground->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
DdErrorCheck(hr, "lpddbackground->Lock() FAILED");
if(FAILED(hr)) return(false);
Error("lpddbackground->Lock - SUCCESS");
UCHAR *imagebuffer = (UCHAR *)ddsd.lpSurface;
if(!(memcpy((void *)imagebuffer, (void *)bitmap.buffer, RES_WIDTH*RES_HEIGHT)))
{
Error("memcpy FAILED");
return(false);
} //end if
Error("memcpy - SUCCESS");
hr=lpddbackground->Unlock(NULL);
DdErrorCheck(hr, "lpddbackground->Unlock() FAILED");
if(FAILED(hr)) return(false);
After this piece of code is executed, the program crashes and it returns to windows. What the hell. I know it''s this piece of code because I''ve made message boxes popup after each function (for debug purposes, of course), and I get all of the previous functions working properly previous to this little doozy- I don''t get a success message after this code, instead, it crashes my program. All I need is a way to get the data from a bitmap (already loaded) onto an offscreen surface. Can anyone point me in the right direction? This is frustrating! I''ve been at it all day... bah!!!
Memcpy is givin' me troubles.. as always.
Alright, so far I''ve gotten a lot complete on my program, however I''ve come across yet another problem using memcpy. I hate that function with an undying passion.... but anyways, this is my problem:
After intializing DirectDraw, loading a bitmap to memory and creating an offscreen surface to hold the bitmap, I''ve tried to copy the data from the bitmap onto the offscreen surface using memcpy. Here''s the code:
Not sure but shouldnt it be:-
memcpy((void *)imagebuffer, (void *)bitmap.buffer, RES_WIDTH*RES_HEIGHT*BYTES_PER_PIXEL)
?
memcpy((void *)imagebuffer, (void *)bitmap.buffer, RES_WIDTH*RES_HEIGHT*BYTES_PER_PIXEL)
?
returns the pointer to the destination memory doesnt it? well it returns something I think. Though yet again not sure.
Like Seaman said mamcpy returns adress to original destination memory and there is no way for checking did the function fail or not.
I tried RES_WIDTH*RES_HEIGHT_*RES_BPP but that didn''t make any sort of difference at all. I took out the if(!(memcpy.. since, as you said, it doesn''t really have a return value that I can assess for errors. Ugh. Any other help?
Your not taking into acount the pitchs.
You should:
for height
memcopy Surfacept,Bitmappt,width
Surfacept+=sfPitch
Bitmappt+=bmPitch
This should prevent wierd memory access
You should:
for height
memcopy Surfacept,Bitmappt,width
Surfacept+=sfPitch
Bitmappt+=bmPitch
This should prevent wierd memory access
....................what?
See, this is why Andre is a crappy author. I've been using the DirectX SDK to learn all this DirectDraw programming and Andre's book for exercises and for certain functions. If he would have written his damn book right the first time, I wouldn't have this urge to kick his ass.
Edited by - Stibmit on July 31, 2001 10:09:27 PM
See, this is why Andre is a crappy author. I've been using the DirectX SDK to learn all this DirectDraw programming and Andre's book for exercises and for certain functions. If he would have written his damn book right the first time, I wouldn't have this urge to kick his ass.
Edited by - Stibmit on July 31, 2001 10:09:27 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement