godot
godot copied to clipboard
`RenderingDevice.free_rid` also frees associated RIDs
Tested versions
Reproduciable in 4.4
System information
Godot v4.4.beta.mono - EndeavourOS SMP PREEMPT_DYNAMIC Sat, 08 Feb 2025 18:54:55 +0000 on Wayland - X11 display driver, Multi-window, 1 monitor - Vulkan (Mobile) - integrated AMD Radeon Graphics (RADV RENOIR) - AMD Ryzen 7 4800U with Radeon Graphics (16 threads)
Issue description
I'm trying to use the rasterization pipeline of RenderingDevice to implement a custom texture, I manage all the created RIDs and whenever a new RID is created, I release the old one. The source code is https://github.com/beicause/GodotMeshTextureRd/blob/44161c240a495e6114aaf41db312f5a86ba64bff/MeshTextureRd.cs
However, I encountered the following error when I change properties and update pipeline:
ERROR: ./servers/rendering/rendering_device.cpp:6111 - Attempted to free invalid ID: xxxxx
It seems that the associated RIDs have already been released. I'm not sure whether this is as expected or a bug. And I can't find relevant documentation about it. Moreover, the document of index_buffer_create states that you need to free the RID, but vertex_array_create doesn't ( RenderingServer.texture_rd_create either). This makes me more confused about which RIDs I should free.
Edit: These are related RID dependencies:
- texture shared depends on with_texture
- framebuffer depends on textures
- vertex_array depends on vertex_buffer
- index_array depends on index_buffer
- uniform_set depends on shader and rids in RDUniform
- render/compute pipeline depends on shader
Steps to reproduce
The following script will print an error ( But it won't if you free fb_rid then free tex_rid, which indicates that freeing tex_rid will also makes fb_rid invalid)
extends Node2D
func _ready() -> void:
var rd := RenderingServer.get_rendering_device()
var format := RDTextureFormat.new()
format.usage_bits = RenderingDevice.TEXTURE_USAGE_SAMPLING_BIT | RenderingDevice.TEXTURE_USAGE_COLOR_ATTACHMENT_BIT
var tex_rid := rd.texture_create( format, RDTextureView.new())
var fb_rid := rd.framebuffer_create([tex_rid])
print(tex_rid,fb_rid)
rd.free_rid(fb_rid)
rd.free_rid(tex_rid)
ERROR: ./servers/rendering/rendering_device.cpp:6111 - Attempted to free invalid ID: <fb_rid>
Minimal reproduction project (MRP)
N/A