Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Crash - CreateSurface

This topic is 6535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, The code below causes my program to crash. Specifically, it doesn''t get past the CreateSurface. No errors, no ''invalid page faults'' or anything, just stops executing... ddsd.dwSize=sizeof(ddsdx); ddsd.dwFlags=DDSD_CAPS/DDSD_HEIGHT/DDSD_WIDTH; ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN; ddsd.dwHeight=64; ddsd.dwWidth=64; DD.Write("DDSURFACEDESC2...ok"); hRet=lpDD->CreateSurface(&ddsd,&Background,NULL); // STOPS HERE DD.Write("CreateSurface...ok"); Oh, by the way, DD is a log file I''m writing to. The ''DDSURFACEDESC2...ok'' gets written to the file, but the ''CreateSurface...ok'' doesn''t. That''s how I''ve narrowed it down to that CreateSurface line. Anybody else have similar problems?

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure what''s causing the problem but I can see errors in your code.

In this line:
ddsd.dwSize=sizeof(ddsdx);
Why do you write sizeof(ddsdx)?
Write ddsd.dwSize=sizeof(ddsd);

And are you absolutely sure that the CreateSurface function isn''t failing? Have you checked return values?

Share this post


Link to post
Share on other sites
quote:
Original post by Mr Cucumber

I''m not sure what''s causing the problem but I can see errors in your code.

In this line:
ddsd.dwSize=sizeof(ddsdx);
Why do you write sizeof(ddsdx)?
Write ddsd.dwSize=sizeof(ddsd);

And are you absolutely sure that the CreateSurface function isn''t failing? Have you checked return values?


Ah, it was ddsdx for all of them, I just changed it to ddsd while posting, and missed one...

I have...

if (hRet!=DD_OK)
{
_ltoa(hRet,ErrorString,10);
MessageBox(hWnd,ErrorString,"OSSFAIL",MB_OK);
}

But in any case, shouldn''t the log file get written to?

Share this post


Link to post
Share on other sites
Well, if CreateSurface is actually crashing, no amount of return value checking will make any difference And that second line of logging will never get executed.

My first guess is this: did you actually zero out the memory of ddsd or ddsdx or whatever you''re using before you started filling in its parameters?

Share this post


Link to post
Share on other sites
Make sure your DD.write is really outputting each time - it may be just sitting in a buffer and giving a false indication of where the error occured. Try DD.write("...ok\n") - the newline may force output.

Share this post


Link to post
Share on other sites
Ro_Akira:

Kylotan is right in about clearing the memory. I was once doing something with DirectSound and forgot to clear the memory of a stucture and I got weird results. Try adding this above your previously posted code:

ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));

Also, I don''t know if this is just because of the forum or not, but you have:

ddsd.dwFlags=DDSD_CAPS/DDSD_HEIGHT/DDSD_WIDTH;

I can only imagine that you mean:

ddsd.dwFlags = DDSD_CAPS / DDSD_HEIGHT / DDSD_WIDTH;

What you had would certainly cause unpredictable results...

Good luck,
-> Briar LoDeran <-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok, nevermind on that last thing. The forum seems to turn pipes into the divided by symbol. I guess that''s why the code tags exist.
    
/
/

-> Briar LoDeran <-

Share this post


Link to post
Share on other sites
DDSURFACEDESC2 ddsdx;
LPDIRECTDRAWSURFACE7 Background=NULL;

.
.
.

ddsdx.dwSize=sizeof(ddsdx);
ZeroMemory(&ddsdx,sizeof(ddsdx));
ddsdx.dwFlags=DDSD_CAPS/DDSD_HEIGHT/DDSD_WIDTH;
ddsdx.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
ddsdx.dwHeight=64;
ddsdx.dwWidth=64;
DD.Write("DDSURFACEDESC2...ok");
hRet=lpDD->CreateSurface(&ddsdx,&Background,NULL); // STOPS HERE
DD.Write("CreateSurface...ok");

DD.Write("CreateOSS...ok");

if (hRet!=DDOK)
{
_ltoa(hRet,ErrorString,10);
MessageBox(hWnd,ErrorString,"OSSFAIL",MB_OK);
}

.
.
.

This is now how the code stands. I tried that ZeroMemory, but it caused no change in the program''s unruley behaviour. I''ve tried that VIDEOMEMORY and SYSTEMMEMORY with dwCaps, in case there was some weird problem to do with that. Didn''t make any difference.

I''m fairly sure that those DD.Write''s are working too. I tried a message box just after the suspected crashline(CreateSurface) and it didn''t appear either. So that''s how I came to that conclusion.

Oh, and the same thing happens (prog. crash), when I do a page flip of the Primary Surface. Don''t know if that''s any help. (Just sounds like more problems to me!)

Anyway, thanks for your replies everyone... and keep them coming please !

Share this post


Link to post
Share on other sites
quote:
Original post by Ro_Akira

ddsdx.dwSize=sizeof(ddsdx);
ZeroMemory(&ddsdx,sizeof(ddsdx));




Er, I believe that should be the other way round shouldn''t it?

i.e. :
ZeroMemory(&ddsdx,sizeof(ddsdx));
ddsdx.dwSize=sizeof(ddsdx);

Well, didn''t make a difference anyway

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!