From d670f8a968ae90585d7590bb1139d26b04712cd3 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 10 Aug 2021 09:21:32 +0200 Subject: [PATCH] Implement material_cache_unref and material_cache_custom_key_unref aswell. --- singleton/prop_cache.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/singleton/prop_cache.cpp b/singleton/prop_cache.cpp index cdc4d05..63d3d47 100644 --- a/singleton/prop_cache.cpp +++ b/singleton/prop_cache.cpp @@ -215,8 +215,26 @@ Ref PropCache::material_cache_get(const Ref &prop) return m; } void PropCache::material_cache_unref(const Ref &prop) { + //get pointer's value as uint64 + uint64_t k = make_uint64_t(*prop); + _material_cache_mutex.lock(); + if (!_material_cache.has(k)) { + _material_cache_mutex.unlock(); + + ERR_PRINT("PropCache::material_cache_unref: can't find cache!"); + + return; + } + + Ref m = _material_cache[k]; + + m->dec_ref_count(); + if (m->get_ref_count() <= 0) { + _material_cache.erase(k); + } + _material_cache_mutex.unlock(); } @@ -250,6 +268,21 @@ Ref PropCache::material_cache_custom_key_get(const uint64_t k void PropCache::material_cache_custom_key_unref(const uint64_t key) { _custom_keyed_material_cache_mutex.lock(); + if (!_material_cache.has(key)) { + _custom_keyed_material_cache_mutex.unlock(); + + ERR_PRINT("PropCache::material_cache_unref: can't find cache!"); + + return; + } + + Ref m = _custom_keyed_material_cache[key]; + + m->dec_ref_count(); + if (m->get_ref_count() <= 0) { + _custom_keyed_material_cache.erase(key); + } + _custom_keyed_material_cache_mutex.unlock(); }