Skip to main content
GameDev.net gamedev.net
🔒 Locked

LPDIRECT3DSURFACE8 problem

Started by Madness Apr 18, 2002 at 7:29 AM 6 replies 600+ views
Original Post
Madness
Madness
yo i got a problem with the LPDIRECT3DSURFACE8 i can get a pointer to it but as soon as i do any functions with it my application gets screwed up ... i get a error like : Unhandled exeption in win32.exe : 0xC0000005:Access Violation. and it doesn''t have to do with any other damn piece of code coz this piece of code alone in a winmain() crashed my app LPDIRECT3DSURFACE8 test; test->Addref(); i mean ... that REALLY should work :-)
Mark Duffill
Mark Duffill
LPDIRECT3DSURFACE8 is a pointer *to* a surface. If you haven't created a surface for the varable to point at it will crash.

Just like the following will fail.

int *a;

(*a) = 1; // a is pointing to an undefined bit of memory.

[edit] ap beat me to the punch line [/edit]

[edited by - Mark Duffill on April 18, 2002 8:39:09 AM]
Madness
Madness
ok i thuink i'm doing that right now , here is the code i'm using , i'm already sure i'm initializing D3D correctly.
and this code comes after my call to BeginScene()
//////
LPDIRECT3DSURFACE8 pSurface = 0;
LoadBitmapToSurface( "Zen.bmp", &pSurface, g_pDevice );

D3DSURFACE_DESC (d3dsd);
pSurface->GetDesc( &d3dsd) ;

POINT DestPoint = { 100, 100};
RECT rect = { 0, 0, d3dsd.Width, d3dsd.Height };

g_pDevice->CopyRects( pSurface, ▭, 1, g_pBackSurface, &DestPoint );

pSurface->Release();
/////

here my compiler gives the same error at the line
pSurface->GetDesc( &d3dsd);

LoadBitmapToSurface is a custom function that fills the surface with the picture information
any suggestions ?

[edited by - madness on April 18, 2002 8:56:55 AM]
Mark Duffill
Mark Duffill
pSurface->Release(); - You are releasing the pointer here.
/////

here my compiler gives the same error at the line
pSurface->GetDesc( &d3dsd);
- you are trying to access a "Null" pointer.

I''d suggest replacing pSurface->Release() with:-

#define SAFE_RELEASE(a) if(a) {(a)->Release();} (a) = NULL;

Then use as follows:-

SAFE_RELEASE(pSurface);
This will release it if its not null, then set it to null. Hopefully this should help catch any bugs.

[Note] this assumes you havn''t explicitly done ->AddRef(); .If you do want to do AddRef() you must do it before you call Release()[/Note]

Sorrow
Sorrow
quote:

LoadBitmapToSurface( "Zen.bmp", &pSurface, g_pDevice );



... Is this a procedure you wrote yourself? I think it''s safe to assume that it isn''t creating the surface so you''ve still got a null pointer (and as a result your program of course crashes as soon as you try to use pSurface.)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.