From 5e8b3f6c4f5250ffa1e1f2bc41da3ef74b91c427 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 21 Nov 2026 22:32:01 -0500 Subject: [PATCH 1/2] Reset all Model and Mesh fields on Unload --- include/MeshUnmanaged.hpp | 2 +- include/ModelUnmanaged.hpp | 3 +-- tests/raylib_cpp_test.cpp | 42 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/include/MeshUnmanaged.hpp b/include/MeshUnmanaged.hpp index 47ee2824..cbcfa7aa 100644 --- a/include/MeshUnmanaged.hpp +++ b/include/MeshUnmanaged.hpp @@ -156,7 +156,7 @@ class MeshUnmanaged : public ::Mesh { void Unload() { if (vboId != nullptr) { ::UnloadMesh(*this); - vboId = nullptr; + set(::Mesh{}); } } diff --git a/include/ModelUnmanaged.hpp b/include/ModelUnmanaged.hpp index 3f1c43be..1f28418f 100644 --- a/include/ModelUnmanaged.hpp +++ b/include/ModelUnmanaged.hpp @@ -95,8 +95,7 @@ class ModelUnmanaged : public ::Model { void Unload() { if (meshes != nullptr || materials != nullptr) { ::UnloadModel(*this); - meshes = nullptr; - materials = nullptr; + set(::Model{}); } } diff --git a/tests/raylib_cpp_test.cpp b/tests/raylib_cpp_test.cpp index d2539e85..72a761da 100644 --- a/tests/raylib_cpp_test.cpp +++ b/tests/raylib_cpp_test.cpp @@ -3,6 +3,7 @@ #include "raylib-assert.h" // clang-format on #include +#include #include int main(int argc, char* argv[]) { @@ -207,6 +208,47 @@ int main(int argc, char* argv[]) { AssertEqual(boundingBox.GetMin(), (raylib::Vector3{9, 8, 7})); } + // Model Unload resets all fields (CPU-only data, no meshes, so no GPU calls) + { + raylib::ModelUnmanaged model; + model.meshes = static_cast<::Mesh*>(MemAlloc(sizeof(::Mesh))); + model.meshMaterial = static_cast(MemAlloc(sizeof(int))); + model.skeleton.boneCount = 1; + model.skeleton.bones = static_cast<::BoneInfo*>(MemAlloc(sizeof(::BoneInfo))); + model.skeleton.bindPose = static_cast<::Transform*>(MemAlloc(sizeof(::Transform))); + model.currentPose = static_cast<::Transform*>(MemAlloc(sizeof(::Transform))); + model.boneMatrices = static_cast<::Matrix*>(MemAlloc(sizeof(::Matrix))); + + model.Unload(); + Assert(model.meshes == nullptr, "Expected meshes to be null after Unload"); + Assert(model.materials == nullptr, "Expected materials to be null after Unload"); + Assert(model.meshMaterial == nullptr, "Expected meshMaterial to be null after Unload"); + Assert(model.skeleton.bones == nullptr, "Expected bones to be null after Unload"); + Assert(model.skeleton.bindPose == nullptr, "Expected bindPose to be null after Unload"); + Assert(model.currentPose == nullptr, "Expected currentPose to be null after Unload"); + Assert(model.boneMatrices == nullptr, "Expected boneMatrices to be null after Unload"); + AssertEqual(model.meshCount, 0); + AssertEqual(model.materialCount, 0); + AssertEqual(model.skeleton.boneCount, 0u); + + // Unloading twice is a no-op. + model.Unload(); + } + + // Model move leaves the moved-from Model empty + { + raylib::Model source; + source.meshes = static_cast<::Mesh*>(MemAlloc(sizeof(::Mesh))); + source.meshMaterial = static_cast(MemAlloc(sizeof(int))); + source.boneMatrices = static_cast<::Matrix*>(MemAlloc(sizeof(::Matrix))); + + raylib::Model target(std::move(source)); + Assert(source.meshes == nullptr, "Expected moved-from meshes to be null"); + Assert(source.meshMaterial == nullptr, "Expected moved-from meshMaterial to be null"); + Assert(source.boneMatrices == nullptr, "Expected moved-from boneMatrices to be null"); + Assert(target.meshes != nullptr, "Expected moved-to meshes to be set"); + } + TraceLog(LOG_INFO, "TEST: raylib-cpp test"); TraceLog(LOG_INFO, "---------------------"); return 0; From b502040aecf5b3a05a2ea1392b024449939e727e Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Sat, 21 Nov 2026 22:35:15 -0500 Subject: [PATCH 2/2] Fix Model test for MSVC --- tests/raylib_cpp_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/raylib_cpp_test.cpp b/tests/raylib_cpp_test.cpp index 72a761da..48348e09 100644 --- a/tests/raylib_cpp_test.cpp +++ b/tests/raylib_cpp_test.cpp @@ -237,7 +237,7 @@ int main(int argc, char* argv[]) { // Model move leaves the moved-from Model empty { - raylib::Model source; + raylib::Model source(::Model{}); source.meshes = static_cast<::Mesh*>(MemAlloc(sizeof(::Mesh))); source.meshMaterial = static_cast(MemAlloc(sizeof(int))); source.boneMatrices = static_cast<::Matrix*>(MemAlloc(sizeof(::Matrix)));