• Advertisement

Archived

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

Crash - CreateSurface

This topic is 6445 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
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
try
ZeroMemory(&ddsdx, sizeof(DDSURFACEDESC2));
instead of
ZeroMemory(&ddsdx,sizeof(ddsdx));
shouldn't make a difference since MSVC is bug free



Edited by - Magmai Kai Holmlor on June 23, 2000 11:40:50 PM

Share this post


Link to post
Share on other sites
Look at the post above mine. There were computers in 1899? Wow. Talk about Y2K problems

If all this fails, you might want to try reformatting you harddisk and reinstalling DirectX. I had a problem with the DX library that came with Andre''s TOTWGPG. The problem is when I call flip, it works, but only once. Say I have a primary surface and a back buffer, after the first flip, the back buffer will be displayed. But on subsequent Flips, the image still remains (i.e., a flip didn''t occur). After I reformatted my harddisk and installed DX 7 (downloaded from microsoft) and recompiled that same program, flip worked fine.

My point is, you might have a buggy installation of DirectX. Has anyone else had a problem like this?

========================================================
If something sounds stupid but works, it's not stupid

Share this post


Link to post
Share on other sites
I''ve tried all those variations with ZeroMemory, but nothing''s worked. I''m doing this in WinMain btw. Well, it''s in a function, but being called at the start of WinMain. I''m only starting DirectX with C++, so I''m just trying to get the basics working first. Sadly, my computer seems to have other ideas!

Oh, and I''ve stopped short of reformating hard-disks or anything like that, since other programs seem to use DirectX ok. E.g. that Alpha Blending program (from the articles here on GDNet). I have noted that, that particular program doesn''t use DirectX7. All my games work alright aswell... not sure if any use DX7 though, think latest needed is DX6.

Not sure if that''s made the problem any clearer. Bah! Even errors with pointers usually give errors!

Share this post


Link to post
Share on other sites
Surely somebody has had this problem before? Bah! I would be first!

Still can''t get this thing to work! My DirectX ''research'' isn''t going to get far at this rate... not even being able to setup an offscreen surface! Gah!

Share this post


Link to post
Share on other sites
Gah! STILL isn''t working.

Um, maybe I could e-mail the code to somebody else, and see if it runs ok on their machine? If somebody would be so kind...

Share this post


Link to post
Share on other sites
Are you sure you have a valid pointer to a Direct Draw Device? Did you check the return value from lpDD. If that is still null you will get it to fail and crash.

If you are doing it in WinMain, has the window been created yet? Does hwnd already exist and is that valid at that point in your code. Just a hunch. I don''t program using the win32, I use MFC.

Share this post


Link to post
Share on other sites
Oh Yeah!

Thanks a bunch for all your replies, but particularly Alek. As it turns out, I was passing my lpDD to my ''StartDirectDraw'' function , not by a reference or pointer, but by value. As a result, my lpDD remained NULL. Now, that wasn''t too clever was it?

Share this post


Link to post
Share on other sites

  • Advertisement