🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

unhandled exception

Started by
2 comments, last by GameDev.net 24 years, 7 months ago
It's been a while since I played with DX, so I might be wrong. Anyway, what immediately strikes me is the lack of a surface depth. You specify width and height, but no color depth...

/Niels

<b>/NJ</b>
Advertisement
On second thought, how is ddsd2 and lpsup...whatever... declared? (gamedev: Why the heck can't you read the previous post while writing an answer - fix it plz. ).

Did you try single stepping to figure out the exact line of the exception?

/Niels

<b>/NJ</b>
Hey guys!
how everybody doing? I hope better than me....
I need some help here =
any time that I tried to create a surface, the compiler gave me this error=
First-chance exception in game01.exe: 0xC0000005: Access Violation.
and here the code with the problem=
ZeroMemory(&ddsd2,sizeof(ddsd2));
ddsd2.dwSize = sizeof(DDSURFACEDESC2);
ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
ddsd2.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
ddsd2.dwWidth = bm.bmWidth;
ddsd2.dwHeight = bm.bmHeight;
if(dd->CreateSurface(&ddsd2,&superficie,NULL) !=DD_OK)
return NULL;
any help will be appreciate

thanks
_José

I think I've seen that error somewhere before... usually it's caused by trying to use a pointer that doesn't point to anything.

Are you just declaring a variable of type "LPDIRECTDRAW"? It is just a pointer - it only holds the memory location of the real variable. So you need to call a function like DirectDrawCreate before you can use it.

If you are calling a function to create the object, maybe that code is failing first? Then the pointer wouldn't point to anything.

The following program will cause the same error:


// Changed these to quotes so they'd
// appear here. Change them back when
// you copy the program.
#include "windows.h"

// Just a simple class
class CMyClass
{
public:
void DoSomething() { m_nData = 5; };

protected:
int m_nData;
};

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
// Create a pointer -
// doesn't point to anything yet.
CMyClass* pNothing;

// Call a member function -
// fails here
pNothing->DoSomething();


// Create an object
pNothing = new CMyClass;

// This will work fine
pNothing->DoSomething();

// Delete the object
delete pNothing;

return 0;
}

Memory access violations are caused by trying to read or write memory you don't have permission to use (because it wasn't allocated). That's why it's called an "access" violation. And that's why the sample program crashes when it tries to set the member variable's value.

Step through your code and see if your LPDIRECTDRAW is NULL after it's been created. If it is, then your creation code is the problem.

P.S. What would happen if they used speech synthesis technology for cryptic compiler/runtime error messages? (instead of text)

[This message has been edited by null_pointer (edited November 17, 1999).]

This topic is closed to new replies.

Advertisement