mirror of https://github.com/axmolengine/axmol.git
Merge pull request #940 from dumganhar/gles20
fixed #1273: Crash appears after clicking closed button in TextureCacheTest.
This commit is contained in:
commit
b662784730
|
@ -46,6 +46,7 @@ set CC_TEST_BIN=tests.exe
|
||||||
set CC_TEST_RES=..\tests\Resources\*.*
|
set CC_TEST_RES=..\tests\Resources\*.*
|
||||||
set CC_HELLOWORLD_RES=..\HelloWorld\Resources\*.*
|
set CC_HELLOWORLD_RES=..\HelloWorld\Resources\*.*
|
||||||
set CC_HELLOLUA_RES=..\HelloLua\Resources\*.*
|
set CC_HELLOLUA_RES=..\HelloLua\Resources\*.*
|
||||||
|
set CC_TESTJS_RES=..\testjs\Resources\*.*
|
||||||
|
|
||||||
if not exist "%CC_TEST_BIN%" (
|
if not exist "%CC_TEST_BIN%" (
|
||||||
echo Can't find the binary "tests.exe", is there build error?
|
echo Can't find the binary "tests.exe", is there build error?
|
||||||
|
@ -59,6 +60,8 @@ echo.
|
||||||
xcopy /E /Y /Q "%CC_TEST_RES%" .
|
xcopy /E /Y /Q "%CC_TEST_RES%" .
|
||||||
xcopy /E /Y /Q "%CC_HELLOWORLD_RES%" .
|
xcopy /E /Y /Q "%CC_HELLOWORLD_RES%" .
|
||||||
xcopy /E /Y /Q "%CC_HELLOLUA_RES%" .
|
xcopy /E /Y /Q "%CC_HELLOLUA_RES%" .
|
||||||
|
xcopy /E /Y /Q "%CC_TESTJS_RES%" .
|
||||||
|
|
||||||
call "%CC_TEST_BIN%"
|
call "%CC_TEST_BIN%"
|
||||||
start http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d-x_Application_Wizard_for_Visual_Studio_User_Guide
|
start http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d-x_Application_Wizard_for_Visual_Studio_User_Guide
|
||||||
goto EOF
|
goto EOF
|
||||||
|
@ -66,4 +69,4 @@ goto EOF
|
||||||
:ERROR
|
:ERROR
|
||||||
pause
|
pause
|
||||||
|
|
||||||
:EOF
|
:EOF
|
||||||
|
|
|
@ -191,6 +191,7 @@ CCEGLView::CCEGLView()
|
||||||
|
|
||||||
CCEGLView::~CCEGLView()
|
CCEGLView::~CCEGLView()
|
||||||
{
|
{
|
||||||
|
CC_SAFE_DELETE(m_pEGL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
|
bool CCEGLView::Create(LPCTSTR pTitle, int w, int h)
|
||||||
|
|
|
@ -65,10 +65,11 @@ typedef struct _ImageInfo
|
||||||
|
|
||||||
static pthread_t s_loadingThread;
|
static pthread_t s_loadingThread;
|
||||||
|
|
||||||
static pthread_mutex_t s_asyncStructQueueMutex;
|
static pthread_mutex_t s_asyncStructQueueMutex;
|
||||||
static pthread_mutex_t s_ImageInfoMutex;
|
static pthread_mutex_t s_ImageInfoMutex;
|
||||||
|
|
||||||
static sem_t* s_pSem = NULL;
|
static sem_t* s_pSem = NULL;
|
||||||
|
static unsigned long s_nAsyncRefCount = 0;
|
||||||
|
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||||
#define CC_ASYNC_TEXTURE_CACHE_USE_NAMED_SEMAPHORE 1
|
#define CC_ASYNC_TEXTURE_CACHE_USE_NAMED_SEMAPHORE 1
|
||||||
|
@ -84,10 +85,10 @@ static sem_t* s_pSem = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static bool need_quit;
|
static bool need_quit = false;
|
||||||
|
|
||||||
static std::queue<AsyncStruct*> *s_pAsyncStructQueue;
|
static std::queue<AsyncStruct*>* s_pAsyncStructQueue = NULL;
|
||||||
static std::queue<ImageInfo*> *s_pImageQueue;
|
static std::queue<ImageInfo*>* s_pImageQueue = NULL;
|
||||||
|
|
||||||
static CCImage::EImageFormat computeImageFormatType(string& filename)
|
static CCImage::EImageFormat computeImageFormatType(string& filename)
|
||||||
{
|
{
|
||||||
|
@ -187,6 +188,8 @@ static void* loadImage(void* data)
|
||||||
sem_destroy(s_pSem);
|
sem_destroy(s_pSem);
|
||||||
#endif
|
#endif
|
||||||
s_pSem = NULL;
|
s_pSem = NULL;
|
||||||
|
delete s_pAsyncStructQueue;
|
||||||
|
delete s_pImageQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -195,13 +198,14 @@ static void* loadImage(void* data)
|
||||||
// implementation CCTextureCache
|
// implementation CCTextureCache
|
||||||
|
|
||||||
// TextureCache - Alloc, Init & Dealloc
|
// TextureCache - Alloc, Init & Dealloc
|
||||||
static CCTextureCache *g_sharedTextureCache;
|
static CCTextureCache *g_sharedTextureCache = NULL;
|
||||||
|
|
||||||
CCTextureCache * CCTextureCache::sharedTextureCache()
|
CCTextureCache * CCTextureCache::sharedTextureCache()
|
||||||
{
|
{
|
||||||
if (!g_sharedTextureCache)
|
if (!g_sharedTextureCache)
|
||||||
|
{
|
||||||
g_sharedTextureCache = new CCTextureCache();
|
g_sharedTextureCache = new CCTextureCache();
|
||||||
|
}
|
||||||
return g_sharedTextureCache;
|
return g_sharedTextureCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +233,6 @@ void CCTextureCache::purgeSharedTextureCache()
|
||||||
CC_SAFE_RELEASE_NULL(g_sharedTextureCache);
|
CC_SAFE_RELEASE_NULL(g_sharedTextureCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* CCTextureCache::description()
|
const char* CCTextureCache::description()
|
||||||
{
|
{
|
||||||
return CCString::stringWithFormat("<CCTextureCache | Number of textures = %u>", m_pTextures->count())->getCString();
|
return CCString::stringWithFormat("<CCTextureCache | Number of textures = %u>", m_pTextures->count())->getCString();
|
||||||
|
@ -298,11 +301,16 @@ void CCTextureCache::addImageAsync(const char *path, CCObject *target, SEL_CallF
|
||||||
pthread_mutex_init(&s_ImageInfoMutex, NULL);
|
pthread_mutex_init(&s_ImageInfoMutex, NULL);
|
||||||
pthread_create(&s_loadingThread, NULL, loadImage, NULL);
|
pthread_create(&s_loadingThread, NULL, loadImage, NULL);
|
||||||
|
|
||||||
CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(CCTextureCache::addImageAsyncCallBack), this, 0, false);
|
|
||||||
|
|
||||||
need_quit = false;
|
need_quit = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (0 == s_nAsyncRefCount)
|
||||||
|
{
|
||||||
|
CCDirector::sharedDirector()->getScheduler()->scheduleSelector(schedule_selector(CCTextureCache::addImageAsyncCallBack), this, 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
++s_nAsyncRefCount;
|
||||||
|
|
||||||
if (target)
|
if (target)
|
||||||
{
|
{
|
||||||
target->retain();
|
target->retain();
|
||||||
|
@ -354,15 +362,8 @@ void CCTextureCache::addImageAsyncCallBack(ccTime dt)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTTURE_DATA
|
||||||
// cache the texture file name
|
// cache the texture file name
|
||||||
if (pImageInfo->imageType == CCImage::kFmtJpg)
|
VolatileTexture::addImageTexture(texture, filename, pImageInfo->imageType);
|
||||||
{
|
|
||||||
VolatileTexture::addImageTexture(texture, filename, CCImage::kFmtJpg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
VolatileTexture::addImageTexture(texture, filename, CCImage::kFmtPng);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// cache the texture
|
// cache the texture
|
||||||
|
@ -375,9 +376,15 @@ void CCTextureCache::addImageAsyncCallBack(ccTime dt)
|
||||||
target->release();
|
target->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete pImage;
|
pImage->release();
|
||||||
delete pAsyncStruct;
|
delete pAsyncStruct;
|
||||||
delete pImageInfo;
|
delete pImageInfo;
|
||||||
|
|
||||||
|
--s_nAsyncRefCount;
|
||||||
|
if (0 == s_nAsyncRefCount)
|
||||||
|
{
|
||||||
|
CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(CCTextureCache::addImageAsyncCallBack), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue