mirror of https://github.com/axmolengine/axmol.git
Fix "TextureCache Test" in js-test crash under Android
This commit is contained in:
parent
ac0a0ed3bb
commit
1a56668cd3
|
@ -43,6 +43,7 @@ namespace cocos2d { namespace network {
|
|||
|
||||
static int sTaskCounter;
|
||||
static int sDownloaderCounter;
|
||||
static bool _registered = false;
|
||||
|
||||
struct DownloadTaskAndroid : public IDownloadTask
|
||||
{
|
||||
|
@ -53,7 +54,6 @@ namespace cocos2d { namespace network {
|
|||
}
|
||||
virtual ~DownloadTaskAndroid()
|
||||
{
|
||||
|
||||
DLLOG("Destruct DownloadTaskAndroid: %p", this);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,8 @@ namespace cocos2d { namespace network {
|
|||
, _impl(nullptr)
|
||||
{
|
||||
// use local static variable make sure native methods registered once
|
||||
static bool _registered = _registerNativeMethods(JniHelper::getEnv());
|
||||
if(!_registered)
|
||||
_registered = _registerNativeMethods(JniHelper::getEnv());
|
||||
DLLOG("Construct DownloaderAndroid: %p", this);
|
||||
JniMethodInfo methodInfo;
|
||||
if (JniHelper::getStaticMethodInfo(methodInfo,
|
||||
|
@ -163,6 +164,7 @@ namespace cocos2d { namespace network {
|
|||
}
|
||||
DownloadTaskAndroid *coTask = iter->second;
|
||||
string str = (errStr ? errStr : "");
|
||||
_taskMap.erase(iter);
|
||||
onTaskFinish(*coTask->task,
|
||||
errStr ? DownloadTask::ERROR_IMPL_INTERNAL : DownloadTask::ERROR_NO_ERROR,
|
||||
errCode,
|
||||
|
@ -170,7 +172,15 @@ namespace cocos2d { namespace network {
|
|||
data
|
||||
);
|
||||
coTask->task.reset();
|
||||
_taskMap.erase(iter);
|
||||
}
|
||||
|
||||
|
||||
void _preloadJavaDownloaderClass()
|
||||
{
|
||||
if(!_registered)
|
||||
{
|
||||
_registered = _registerNativeMethods(JniHelper::getEnv());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace cocos2d::network
|
||||
|
|
|
@ -50,5 +50,8 @@ namespace cocos2d { namespace network
|
|||
std::unordered_map<int, DownloadTaskAndroid*> _taskMap;
|
||||
};
|
||||
|
||||
// Load java downloader class from main thread, to void addImageAsync function
|
||||
// perform in sub-thread cause java downloader unusable
|
||||
void _preloadJavaDownloaderClass();
|
||||
}} // namespace cocos2d::network
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ THE SOFTWARE.
|
|||
#include "renderer/ccGLStateCache.h"
|
||||
#include "2d/CCDrawingPrimitives.h"
|
||||
#include "platform/android/jni/JniHelper.h"
|
||||
#include "network/CCDownloader-android.h"
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
@ -81,6 +82,7 @@ JNIEXPORT void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, j
|
|||
director->getEventDispatcher()->dispatchEvent(&recreatedEvent);
|
||||
director->setGLDefaultValues();
|
||||
}
|
||||
cocos2d::network::_preloadJavaDownloaderClass();
|
||||
}
|
||||
|
||||
JNIEXPORT jintArray Java_org_cocos2dx_lib_Cocos2dxActivity_getGLContextAttrs(JNIEnv* env, jobject thiz)
|
||||
|
|
Loading…
Reference in New Issue