bkaradzic/bgfx

readTexture calls will crash when queued against released textures

EvilTrev opened this issue · 1 comments

Describe the bug
A resize event or manual call that causes textures to be free'd when a readTexture call is queued in the command buffer will lead to a crash (at least with metal, but perhaps other platforms too). Crash ends up here:

// Copying Data from a Texture Image
void getBytes(void* _pixelBytes, NSUInteger _bytesPerRow, NSUInteger _bytesPerImage, MTLRegion _region, NSUInteger _mipmapLevel, NSUInteger _slice) const
{
	[m_obj getBytes:_pixelBytes bytesPerRow:_bytesPerRow bytesPerImage:_bytesPerImage fromRegion:_region mipmapLevel:_mipmapLevel slice:_slice];
}

It seems like this should be hazard tracked, or perhaps the post command buffer should be stripped of CommandBuffer::ReadTexture commands that reference handles being destroyed?

To Reproduce
Steps to reproduce the behavior:

  1. Schedule a bgfx::readTexture each frame on a texture recreated on resize, or free'd in some other way.
  2. Trigger resize, destroy/recreate textures that are due to be read to.

Closing until I do a little more testing, want to make sure this isn't something getting stomped.