Ownership of Models + Double Frees
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Domain
- computer-graphics
Research direction
Start with the models example and the Model destructor, then trace UnloadModel and UnloadMesh in rmodel.c through the shown unload sequence. Reproduce the double free and determine how ownership is shared between the wrapper and raylib. Done means the model and mesh resources are released once without the corruption error or duplicate VAO unload.
Written by the indexing model from the issue text.
Description
When loading the Models with Mesh the ownership is not clear and the mash(es)(?) got double freed.
Logs
INFO: TEXTURE: [ID 2] Texture loaded successfully (128x128 | GRAY_ALPHA | 1 mipmaps)
INFO: FONT: Default font loaded successfully (224 glyphs)
INFO: FILEIO: [resources/cubicmap.png] File loaded successfully
INFO: IMAGE: Data loaded successfully (32x16 | R8G8B8 | 1 mipmaps)
INFO: TEXTURE: [ID 3] Texture loaded successfully (32x16 | R8G8B8 | 1 mipmaps)
INFO: VAO: [ID 2] Mesh uploaded successfully to VRAM (GPU)
INFO: FILEIO: [resources/cubicmap_atlas.png] File loaded successfully
INFO: IMAGE: Data loaded successfully (256x256 | R8G8B8A8 | 1 mipmaps)
INFO: TEXTURE: [ID 4] Texture loaded successfully (256x256 | R8G8B8A8 | 1 mipmaps)
INFO: TIMER: Target time per frame: 16.667 milliseconds
INFO: TEXTURE: [ID 2] Unloaded texture data from VRAM (GPU)
INFO: SHADER: [ID 3] Default shader unloaded successfully
INFO: TEXTURE: [ID 1] Default texture unloaded successfully
double free or corruption (!prev)
INFO: Window closed successfully
INFO: TEXTURE: [ID 4] Unloaded texture data from VRAM (GPU)
INFO: VAO: [ID 2] Unloaded vertex array data from VRAM (GPU)
INFO: VAO: [ID 2] Unloaded vertex array data from VRAM (GPU)
models example
// Define the camera to look into our 3d world
raylib::Camera camera({ 0.2f, 0.4f, 0.2f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f);
raylib::Texture cubicmap;
raylib::Model model;
raylib::Texture texture;
// load from imMap
{
raylib::Image imMap;
imMap.Load("resources/cubicmap.png"); // Load cubicmap image (RAM)
cubicmap.Load(imMap); // Convert image to texture to display (VRAM)
raylib::Mesh mesh = raylib::Mesh::Cubicmap(imMap, Vector3{1.0f, 1.0f, 1.0f});
model.Load(mesh);
// NOTE: By default each cube is mapped to one part of texture atlas
texture.Load("resources/cubicmap_atlas.png"); // Load map texture
model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; // Set map diffuse texture
}
// Error happen at the end of the main
~Model() {
Unload(); ///< error here ::UnloadModel(*this);
}
rmodel.c
// Unload model (meshes/materials) from memory (RAM and/or VRAM)
// NOTE: This function takes care of all model elements, for a detailed control
// over them, use UnloadMesh() and UnloadMaterial()
void UnloadModel(Model model)
{
// Unload meshes
for (int i = 0; i < model.meshCount; i++) UnloadMesh(model.meshes[i]); ///< here
...
// Unload mesh from memory (RAM and VRAM)
void UnloadMesh(Mesh mesh)
{
// Unload rlgl mesh vboId data
rlUnloadVertexArray(mesh.vaoId);
if (mesh.vboId != NULL) for (int i = 0; i < MAX_MESH_VERTEX_BUFFERS; i++) rlUnloadVertexBuffer(mesh.vboId[i]);
RL_FREE(mesh.vboId);
RL_FREE(mesh.vertices); ///< error here
- Dominant language
- C++
- Stars
- 960
- Forks
- 120
- Avg merge
- 10m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RobLoach/raylib-cpp
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
RobLoach/raylib-cpp#425 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
RobLoach/raylib-cpp#427 ·
-
Code gen Open
Difficulty 5/5 Over a week Newbie friendliness 30/100
RobLoach/raylib-cpp#415 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
RobLoach/raylib-cpp#370 · 1 comment ·
-
SDF Font Support Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
RobLoach/raylib-cpp#366 · 3 comments ·
All issues in RobLoach/raylib-cpp
Similar issues
-
ai_reviewed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ydb-platform/ydb#53869 · 3 comments ·
-
bug cert blocker needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
project-chip/connectedhomeip#74373 ·
-
upstream update
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conan-io/conan-center-index#31035 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 85/100
vllm-project/vllm-ascend#17329 ·