From f3d9effb838255e213d986daed69a87c94eb5a61 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Wed, 2 Jun 2021 16:47:05 +0200 Subject: [PATCH] fix double free for model animation unloading --- lib/Ray/sources/Utils/Cache.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Ray/sources/Utils/Cache.hpp b/lib/Ray/sources/Utils/Cache.hpp index f30fa3ff..a1eef87a 100644 --- a/lib/Ray/sources/Utils/Cache.hpp +++ b/lib/Ray/sources/Utils/Cache.hpp @@ -60,11 +60,13 @@ namespace RAY { {}; std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter) { + ::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter); + unsigned int animCount = *counter; + if (this->_cache.find(path) == this->_cache.end()) this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>( - this->_dataLoader(path.c_str(), counter), [this, counter](::ModelAnimation *p) { - this->_dataUnloader(p, *counter); - delete p; + animations, [this, animCount](::ModelAnimation *p) { + this->_dataUnloader(p, animCount); })); return _cache[path]; };