Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#Actualmax343

Posted 26 December 2012 - 04:00 AM


That looks useful for debugging, but how would you rewrite this code so that it doesn't cause the assert to fail?



GraphicsDevice device;
Texture* texture1 = device.CreateTexture(...);
device.SetTexture(texture1);
delete texture1;
Texture* texture2 = device.CreateTexture(...); // device dereferences dangling pointer; crash

 
 



This is problematic. Best way to deal with this is to let GraphicsDevice to deallocate the texture (instead of leaving it to Texture). If deallocating currently bound texture, then just reset the texture pointer to NULL.
There's also the option of using one texture unit as a temporary unit for all those things like creating textures. This is less pretty, and leaves you with one unit less, but it'll help minimize the amount of rebinds.

#1max343

Posted 26 December 2012 - 04:00 AM

<blockquote class="ipsBlockquote" data-author="IncidentRay" data-cid="5014304"><p>&nbsp;<br />That looks useful for debugging, but how would you rewrite this code so that it doesn't cause the assert to fail?</p><pre class="_prettyXprint _lang-auto _linenums:0">

GraphicsDevice device;
Texture* texture1 = device.CreateTexture(...);
device.SetTexture(texture1);
delete texture1;
Texture* texture2 = device.CreateTexture(...); // device dereferences dangling pointer; crash
</pre>&nbsp;<br /><p><br /></p></blockquote><br />This is problematic. Best way to deal with this is to let GraphicsDevice to deallocate the texture (instead of leaving it to Texture). If deallocating currently bound texture, then just reset the texture pointer to NULL.<br />There's also the option of using one texture unit as a temporary unit for all those things like creating textures. This is less pretty, and leaves you with one unit less, but it'll help minimize the amount of rebinds.

PARTNERS