godotengine / godotengine/godot
TextureStorage::texture_debug_usage and MeshStorage::mesh_debug_usage are not thread-safe
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- current master @ 3c9d03b8755968ae305b8cfebe886c56402cb044
### System information
macOS Sequoia (15.6.0) - Multi-window, 1 monitor - Metal (Forward+) - integrated Apple M4 Max (Apple9) - Apple M4 Max (16 threads)
### Issue description
texture_debug_usage and mesh_debug_usage are not thread-safe. While `get_owned_list()` is thread-safe, iterating through the list is not. The mutex is not held while iterating through the list, which means that textures/meshes can be freed during iteration, which can lead to a segfault when de-referencing them while populating the info objects.
This can be likely be fixed by just locking the mutex before iterating through the list.
### Steps to reproduce
1. constantly call either function on a task thread while loading and unloading scenes on the main thread
2. Eventually, you'll get a segfault.
### Minimal reproduction project (MRP)
N/A
Contributor guide
Research direction
Start by locating TextureStorage::texture_debug_usage and MeshStorage::mesh_debug_usage, then read how get_owned_list() and its returned lists are used during iteration. Reproduce the concurrent task-thread calls while loading and unloading scenes, and verify both functions remain safe without segfaults during that workload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100