Fix issue with external textures being freed by Godot #56148
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fix applies to Godot 3.x only.
I'm not sure what changed or when but this issue was around for awhile. I think this originally worked because the allocation size was checked as part of the cleanup.
Anyway, the situation here is when an XR Interface supplies the textures into which a viewport is rendered instead of us using Godots own textures. A texture object is created that wraps around the supplier OpenGL texture id so we can do stuff like using the texture to render out a preview.
During cleanup of a render target this texture object is destroyed and it destroys it's OpenGL texture alongside it. In this case it shouldn't because this texture was never created by Godot, it was created by the XR interface. If the render target is cleaned up because settings on the viewport change that require re-creating it with different settings, the result is flashing inside of the headset as one of the textures in the texture chain has gone byebye.
The fix here is really simple, in the two places in each driver where this texture is destroyed, we set the
tex_id
value to zero preventing it being destroyed by Godot (it will be cleaned up by the plugin when required).