Jump to content
  • Advertisement

Archived

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

Madness

LPDIRECT3DSURFACE8 problem

This topic is 5939 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

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 :-)

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Don''t you have to set the long pointer to a direct 3d surface before you can call a method? Just creating a pointer pointing at a random location in memory will give you access violations if you don''t set the address that it points to, or at least.. that would make sense.

Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Didn''t i just say that :D Don''t you hate when people post while you''re responding :C

Billy - BillyB@mrsnj.com

Share this post


Link to post
Share on other sites
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, &rect, 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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
damn thx guys for the replies. but that doesn''t seen to be the problem. but i''ll keep lookin.

thx anyway

Share this post


Link to post
Share on other sites
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.)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!