Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualIncidentRay

Posted 25 December 2012 - 08:22 PM

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

 

 

Should I just just add a device.SetTexture(NULL) call before deleting the texture1 object?  This could become quite tedious in the generic case, with multiple texture units, though.  For example, before deleting any texture you would have to do,

for (unsigned i = 0; i < device.GetNumTextureUnits(); ++i) {
    if (device.GetTexture(i) == texture) {
        device.SetTexture(i, NULL);
    }
}

#1IncidentRay

Posted 25 December 2012 - 08:22 PM

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

 

Should I just just add a device.SetTexture(NULL) call before deleting the texture1 object?  This could become quite tedious in the generic case, with multiple texture units, though.  For example, before deleting any texture you would have to do,

for (unsigned i = 0; i < device.GetNumTextureUnits(); ++i) {
    if (device.GetTexture(i) == texture) {
        device.SetTexture(i, NULL);
    }
}

PARTNERS