[email protected] 8 years ago
parent
commit
b060d40cde

+ 18 - 2
oxygine/src/oxygine/MaterialCache.cpp

@@ -5,8 +5,6 @@ namespace oxygine
 {
     MaterialX* MaterialCache::clone_(const MaterialX& other)
     {
-        //OX_ASSERT(core::isMainThread());
-
         MutexAutoLock alock(_lock);
 
         size_t hash;
@@ -46,8 +44,26 @@ namespace oxygine
         return copy;
     }
 
+    void MaterialCache::removeUnused()
+    {
+        MutexAutoLock alock(_lock);
+
+        //std::pair<materials::iterator, materials::iterator> it = _materials.begin();
+
+        materials fresh;
+        for (auto it = _materials.begin(); it != _materials.end(); it++) {
+            if (it->second->_ref_counter > 1)
+            {
+                fresh.insert(std::make_pair(it->second->_hash, it->second));
+            }
+        }
+
+        std::swap(fresh, _materials);
+    }
+
     void MaterialCache::clear()
     {
+        MutexAutoLock alock(_lock);
         _materials.clear();
     }
 

+ 1 - 0
oxygine/src/oxygine/MaterialCache.h

@@ -31,6 +31,7 @@ namespace oxygine
         }
 
         void clear();
+        void removeUnused();
         size_t getTotalMaterials() const { return _materials.size(); }
 
     protected:

+ 1 - 0
oxygine/src/oxygine/core/oxygine.cpp

@@ -797,6 +797,7 @@ namespace oxygine
             InputText::stopAnyInput();
 #endif
 
+            rsCache().reset();
             _threadMessages.clear();
             _uiMessages.clear();