Jump to content
  • Advertisement
Sign in to follow this  
Mr Kickass

Question on surfaces

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

I have a class that holds a texture. A function in the class renders to the surface of the texture -> I get the surface using GetCubeMapSurface(). Later I access the surface using GetCubeMapSurface() again (outside of the class: the texture is a global) and 1) If I Release() the surface after rendering it in the class function there is an exception on GetCubeMapSurface() later on. 2) If I don't the program freezes after a couple seconds (it is being rendered every frame - the actual IDirect3DCubeTexture9 is also being created each frame but it is being released every frame too). Why does releasing the "summoned" surface remove it completly from the texture? The documentation says GetCubeMapSurface() increases the reference count so calling release() once after calling GetCubeMapSurface() shouldn't get rid of the actual surface stored in the texture right? How do I get around this? Is the only way to have a member variable for the surface and release it after all work is done with it for that frame or can I retain the surface in the texture without crashing?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Mr Kickass
I have a class that holds a texture.
<snip>
the texture is a global

How can both of these be true at the same time? Either the class you're talking about contains the texture, or it is global. Or is it that your class contains a pointer to the global texture?

In any case, perhaps you're running into some kind of scoping issue. You might be in a situation where your code is operating on different texture pointers and when it calls Release on the surface, the surface it is refering to may not be the exact same one that had its reference count increased.

In general, you should both increment and decrement the reference count of an object from the same scope level. For example, if one object increments the reference count, then it is that objects responsibility to decrement the reference count. The same could hold true for a function if possible. Avoid situations where one object increments a reference count and some other object is responsible for decrementing it, because it is too easy for this situation to cause problems.

neneboricua

Share this post


Link to post
Share on other sites
Sorry I meant the texture is a public member varaible, so that later on I am accessing it like Object.m_texture->GetCubeSurfaceMap(). No other objects associate with this texture.

Each frame GenerateMap() is called - in generate map I call CreateCubeTexture (whatever it is called anyway).

In GenerateMap() I render to each surface of the cube texture, using the same LPDIRECT3DSURFACE9 pointer (I call it "target").

After each draw command I release the surface (target->Release();) and use the "target" pointer again to draw to another surface on the cube.

Then later on there will be an exception when I try to pull that surface out of the texture by doing a Object.m_texture->GetCubeSurfaceMap().

If I don't release target after each draw, it crashes after a few seconds.

Also I release the LPDIRECT3DCUBETEXTURE9 after I am done with the frame, but this is done outside of the GenerateMap() function.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mr Kickass
Each frame GenerateMap() is called - in generate map I call CreateCubeTexture (whatever it is called anyway).

This is not good. Creating and destroying a texture every frame will kill your performance. It is also a good way to have memory leaks because it is easier to accidentally forget to release an object.

You should create the texture during initialization or when the level is loading, render to it every frame, and release it when the texture is no longer needed.
Quote:
Original post by Mr Kickass
After each draw command I release the surface (target->Release();) and use the "target" pointer again to draw to another surface on the cube.

Have you had a look at the CubeMap sample that comes with the SDK? That sample shows exactly how to do this kind of thing. Even though it uses shaders, the idea about how to render to the surfaces of the cube map are the same reguardless of if you're using shaders or the fixed function pipeline.
Quote:
Original post by Mr Kickass
Then later on there will be an exception when I try to pull that surface out of the texture by doing a Object.m_texture->GetCubeSurfaceMap().

If I don't release target after each draw, it crashes after a few seconds.

Are you checking the return values of all the DirectX functions you're calling? You're running with the Debug Runtime, right? Do you get any messages in the debug spew? If you're not sure what I'm talking about, take a look at the Forum FAQ for info on how to use the debug spew. When DirectX encounters an error it not only returns an error code, but also prints out a text string to the debug spew describing what why the error happened.

neneboricua

Share this post


Link to post
Share on other sites
OK, my code was nearly identical to the sample. Turns out the problem was along the lines of sending the wrong face enumerated values to get the faces, so I wasn't getting the right faces. Though I don't see how that could have caused these problems. Oh well it works now. Strange problem. Thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!