Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion include/ModelAnimation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ModelAnimation : public ::ModelAnimation {
}
ModelAnimation result(modelAnimations[index]);
modelAnimations[index].keyframePoses = nullptr;
modelAnimations[index].keyframeCount = 0;
::UnloadModelAnimations(modelAnimations, count);
return result;
}
Expand Down Expand Up @@ -103,9 +104,14 @@ class ModelAnimation : public ::ModelAnimation {
*/
void Unload() {
if (keyframePoses != nullptr) {
::UnloadModelAnimations(this, 1);
// Free the poses directly, as ::UnloadModelAnimations() would also free this object.
for (int i = 0; i < keyframeCount; i++) {
RL_FREE(keyframePoses[i]);
}
RL_FREE(keyframePoses);
keyframePoses = nullptr;
}
keyframeCount = 0;
}

static void Unload(ModelAnimation* modelAnimation, int count) { ::UnloadModelAnimations(modelAnimation, count); }
Expand Down
31 changes: 31 additions & 0 deletions tests/raylib_cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "raylib-assert.h"
// clang-format on
#include <string>
#include <utility>
#include <vector>

int main(int argc, char* argv[]) {
Expand Down Expand Up @@ -187,6 +188,36 @@ int main(int argc, char* argv[]) {
AssertEqual(text.ToString().substr(0, 5), "Lorem");
}

// ModelAnimation
{
std::string animFile = path + "/resources/guyanim.iqm";
int count = raylib::ModelAnimation::LoadCount(animFile);
AssertGreater(count, 0);

{
// The vector going out of scope must unload each animation without freeing the vector's storage.
std::vector<raylib::ModelAnimation> anims = raylib::ModelAnimation::Load(animFile);
AssertEqual(static_cast<int>(anims.size()), count);
AssertGreater(anims[0].GetKeyframeCount(), 0);
AssertNotNull(anims[0].GetKeyframePoses());

anims[0].Unload();
AssertNull(anims[0].GetKeyframePoses());
AssertEqual(anims[0].GetKeyframeCount(), 0);
}

{
raylib::ModelAnimation anim = raylib::ModelAnimation::Load(animFile, 0);
AssertGreater(anim.GetKeyframeCount(), 0);
AssertNotNull(anim.GetKeyframePoses());

raylib::ModelAnimation moved(std::move(anim));
AssertNull(anim.GetKeyframePoses());
AssertEqual(anim.GetKeyframeCount(), 0);
AssertNotNull(moved.GetKeyframePoses());
}
}

// BoundingBox
{
::Vector3 min = {1, 2, 3};
Expand Down
Binary file added tests/resources/guyanim.iqm
Binary file not shown.
Loading