From c96bd9a4dfbbe67eaf57a368925ddc88c375a717 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Tue, 17 May 2016 12:06:28 +0800 Subject: [PATCH] Resolve local reference leak and function order --- cocos/platform/CCImage.h | 30 +++++++++---------- .../local-storage/LocalStorage-android.cpp | 16 ++++++---- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h index 3bbc3618c0..de8466db91 100644 --- a/cocos/platform/CCImage.h +++ b/cocos/platform/CCImage.h @@ -100,6 +100,21 @@ public: UNKNOWN }; + /** + * Enables or disables premultiplied alpha for PNG files. + * + * @param enabled (default: true) + */ + static void setPNGPremultipliedAlphaEnabled(bool enabled) { PNG_PREMULTIPLIED_ALPHA_ENABLED = enabled; } + + /** treats (or not) PVR files as if they have alpha premultiplied. + Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is + possible load them as if they have (or not) the alpha channel premultiplied. + + By default it is disabled. + */ + static void setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied); + /** @brief Load the image from the specified path. @param path the absolute file path. @@ -145,21 +160,6 @@ public: */ bool saveToFile(const std::string &filename, bool isToRGB = true); - /** - * Enables or disables premultiplied alpha for PNG files. - * - * @param enabled (default: true) - */ - static void setPNGPremultipliedAlphaEnabled(bool enabled) { PNG_PREMULTIPLIED_ALPHA_ENABLED = enabled; } - - /** treats (or not) PVR files as if they have alpha premultiplied. - Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is - possible load them as if they have (or not) the alpha channel premultiplied. - - By default it is disabled. - */ - static void setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied); - protected: #if defined(CC_USE_WIC) bool encodeWithWIC(const std::string& filePath, bool isToRGB, GUID containerFormat); diff --git a/cocos/storage/local-storage/LocalStorage-android.cpp b/cocos/storage/local-storage/LocalStorage-android.cpp index d3dc6e5b37..89768115ed 100644 --- a/cocos/storage/local-storage/LocalStorage-android.cpp +++ b/cocos/storage/local-storage/LocalStorage-android.cpp @@ -96,13 +96,19 @@ bool localStorageGetItem( const std::string& key, std::string *outItem ) jstring jret = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, jkey); if (jret == nullptr) { + t.env->DeleteLocalRef(jret); + t.env->DeleteLocalRef(jkey); + t.env->DeleteLocalRef(t.classID); return false; } - outItem->assign(JniHelper::jstring2string(jret)); - t.env->DeleteLocalRef(jret); - t.env->DeleteLocalRef(jkey); - t.env->DeleteLocalRef(t.classID); - return true; + else + { + outItem->assign(JniHelper::jstring2string(jret)); + t.env->DeleteLocalRef(jret); + t.env->DeleteLocalRef(jkey); + t.env->DeleteLocalRef(t.classID); + return true; + } } else {