[email protected] 8 years ago
parent
commit
3632ffb536

+ 1 - 1
examples/Demo/src/example.cpp

@@ -168,7 +168,7 @@ void example_init()
     //Load resources in xml file
     resources.loadXML("xmls/res.xml");
     Test::init();
-    
+
     Test::instance = new TestActor;
     getStage()->addChild(Test::instance);
 

+ 11 - 8
oxygine/src/oxygine/MaterialCache.cpp

@@ -5,28 +5,31 @@ namespace oxygine
 {
     MaterialX* MaterialCache::clone_(const MaterialX& other)
     {
-        OX_ASSERT(core::isMainThread());
+        //OX_ASSERT(core::isMainThread());
+
+        MutexAutoLock alock(_lock);
+
         size_t hash;
         MaterialX::compare cm;
         other.update(hash, cm);
 
 
         materials::iterator itl = _materials.lower_bound(hash);
-                
+
         if (itl != _materials.end())
         {
-            MaterialX *sec = itl->second.get();
-            if (cm(sec, &other))
+            MaterialX* sec = itl->second.get();
+            if (cm == sec->_compare && cm(sec, &other))
                 return sec;
 
             ++itl;
 
             //same hash but not same object
             materials::iterator ith = _materials.upper_bound(hash);
-            for(; itl != ith; itl++)
-            { 
-                MaterialX *sec = itl->second.get();
-                if (cm(sec, &other))
+            for (; itl != ith; itl++)
+            {
+                MaterialX* sec = itl->second.get();
+                if (cm == sec->_compare && cm(sec, &other))
                     return sec;
             }
         }

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

@@ -2,6 +2,7 @@
 #include "oxygine-include.h"
 #include "core/ref_counter.h"
 #include "core/intrusive_ptr.h"
+#include "core/Mutex.h"
 #include <vector>
 #include <unordered_map>
 
@@ -36,6 +37,8 @@ namespace oxygine
         typedef std::unordered_multimap<size_t, spMaterialX> materials;
         materials _materials;
 
+        Mutex _lock;
+
         MaterialX* clone_(const MaterialX& other);
     };
 

+ 13 - 13
oxygine/src/oxygine/core/android/jniUtils.cpp

@@ -45,11 +45,11 @@ namespace oxygine
             _jUtils = (jclass)env->NewGlobalRef(env->FindClass("org/oxygine/lib/Utils"));
             JNI_NOT_NULL(_jUtils);
 
-			_jUtils_getTimeUTCMS = env->GetStaticMethodID(_jUtils, "getTimeUTCMS", "()J");
-			JNI_NOT_NULL(_jUtils_getTimeUTCMS);
+            _jUtils_getTimeUTCMS = env->GetStaticMethodID(_jUtils, "getTimeUTCMS", "()J");
+            JNI_NOT_NULL(_jUtils_getTimeUTCMS);
 
-			_jUtils_getFreeSpace = env->GetStaticMethodID(_jUtils, "getFreeSpace", "(Ljava/lang/String;)J");
-			JNI_NOT_NULL(_jUtils_getFreeSpace);
+            _jUtils_getFreeSpace = env->GetStaticMethodID(_jUtils, "getFreeSpace", "(Ljava/lang/String;)J");
+            JNI_NOT_NULL(_jUtils_getFreeSpace);
 
             _jUtils_getLanguage = env->GetStaticMethodID(_jUtils, "getLanguage", "()Ljava/lang/String;");
             JNI_NOT_NULL(_jUtils_getLanguage);
@@ -124,17 +124,17 @@ namespace oxygine
     }
 
 
-	int64			jniGetFreeSpace(const char *path)
-	{
-		JNIEnv* env = jniGetEnv();
-		LOCAL_REF_HOLDER(env);
+    int64           jniGetFreeSpace(const char* path)
+    {
+        JNIEnv* env = jniGetEnv();
+        LOCAL_REF_HOLDER(env);
+
+        jstring jarg = env->NewStringUTF(path);
+        jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getFreeSpace, jarg);
+        return value;
 
-		jstring jarg = env->NewStringUTF(path);
-		jlong value = env->CallStaticLongMethod(_jUtils, _jUtils_getFreeSpace, jarg);
-		return value;
 
-		
-	}
+    }
 
     bool            jniExit()
     {

+ 1 - 1
oxygine/src/oxygine/core/android/jniUtils.h

@@ -18,7 +18,7 @@ namespace oxygine
     std::string     jniGetPackage();
     bool            jniIsNetworkAvailable();
 
-	int64			jniGetFreeSpace(const char *);
+    int64           jniGetFreeSpace(const char*);
 
     bool            jniExit();
     void            jniRestartApp();

+ 1 - 1
oxygine/src/oxygine/core/ios/ios.h

@@ -16,6 +16,6 @@ namespace oxygine
 
     void iosGetMemoryUsage(size_t& a);
     void iosNavigate(const char*);
-    
+
     int64 iosGetFreeDiskspace();
 }

+ 9 - 9
oxygine/src/oxygine/core/oxygine.cpp

@@ -1020,20 +1020,20 @@ namespace oxygine
         return true;
     }
 
-	int64 getFreeSpace(const char *fullpath /*= 0*/)
-	{
+    int64 getFreeSpace(const char* fullpath /*= 0*/)
+    {
 #ifdef __ANDROID__
-		if (fullpath)
-			return jniGetFreeSpace(fullpath);
-		return jniGetFreeSpace(file::wfs().getFullPath("").c_str());
+        if (fullpath)
+            return jniGetFreeSpace(fullpath);
+        return jniGetFreeSpace(file::wfs().getFullPath("").c_str());
 #elif __APPLE__
         return iosGetFreeDiskspace();
 #endif
-        
-		return std::numeric_limits<int64>::max();
-	}
 
-	std::string     getLanguage()
+        return std::numeric_limits<int64>::max();
+    }
+
+    std::string     getLanguage()
     {
 #ifdef __ANDROID__
         return jniGetLanguage();

+ 1 - 1
oxygine/src/oxygine/core/oxygine.h

@@ -32,7 +32,7 @@ namespace oxygine
     bool            isNetworkAvailable();
 
 
-	int64			getFreeSpace(const char *fullpath = 0);
+    int64           getFreeSpace(const char* fullpath = 0);
 
     /**returns locale. ISO 639-1 */
     std::string     getLanguage();