[Solved] app crashes on resuming activity in android.

[Solved] app crashes on resuming activity in android.
0.0 0


From my cocos2dx game I am lauching another acitvity for result and when I return to the game-activity it crashes with the following stack. By adding logs I checked that




execute successfully and then the app crashes. Similar, behaviour is noticed when I pause the app by pressing home button and reopen it. But in that case the stack trace points to the


03-25 12:46:49.659: D/cocos2d-x debug info(21764): AppDelegate::applicationWillEnterForeground done
03-25 12:46:49.739: I/GLThread(21764): noticed surfaceView surface acquired tid=16
03-25 12:46:49.739: W/EglHelper(21764): start() tid=16
03-25 12:46:49.769: W/EglHelper(21764): createContext com.google.android.gles_jni.EGLContextImpl@405924d8 tid=16
03-25 12:46:49.769: I/Main thread(21764): onWindowResize waiting for render complete from tid=16
03-25 12:46:49.769: W/GLThread(21764): egl createSurface
03-25 12:46:49.769: W/EglHelper(21764): createSurface() tid=16
03-25 12:46:49.769: W/GLThread(21764): onSurfaceCreated
03-25 12:46:50.119: D/cocos2d-x debug info(21764): reload all texture
03-25 12:46:50.289: W/GLThread(21764): onSurfaceChanged(320, 240)

@ * Crash dump:*
Build fingerprint: ‘samsung/GT-S5670/GT-S5670:2.3.4/GINGERBREAD/XWKQ2:user/release-keys’ pid: 20072, tid: 20083 >>> com.xxxx.yyyo <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 482b7000
Stack frame #00 pc 0000cd8c /system/lib/libc.so
Stack frame #01 pc 00168cde /mnt/asec/com.xxxx.yyyo-2/lib/libgame.so: Routine *initWithRawData in D:/Dev/cocos2d-2.0-x-2.0.4/yyyo-21mar/proj.android/…/libs/cocos2dx/platform/CCImageCommon_cpp.h:593
Stack frame #02 pc 00168174 /mnt/asec/com.xxxx.yyyo-2/lib/libgame.so: Routine initWithImageData in D:/Dev/cocos2d-2.0-x-2.0.4/yyyo-21mar/proj.android/…/libs/cocos2dx/platform/CCImageCommon_cpp.h:148@

UPDATE Tried to emulate the same behavior in Visual Studio and came up with the call stack
libcocos2d.dll!cocos2d::CCImage::_initWithRawData(void * pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent) Line 576 libcocos2d.dll!cocos2d::CCImage::initWithImageData(void * pData, int nDataLen, cocos2d::CCImage::EImageFormat eFmt, int nWidth, int nHeight, int nBitsPerComponent) Line 126 C++ libcocos2d.dll!cocos2d::CCTextureCache::addImage(const char * path) Line 440 C++ libcocos2d.dll!cocos2d::CCSprite::initWithFile(const char * pszFilename) Line 254 C++ libcocos2d.dll!cocos2d::CCSprite::create(const char * pszFileName) Line 104 C++ Game.win32.exe!Ball::Ball(b2World * world, std::map<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >,JSONValue *,std::less<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > >,std::allocator<std::pair<std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> > const ,JSONValue *> > > jBall, float boxScaleFactor) Line 20 C++ . . . Game.win32.exe!Game::singleton() Line 27 C++ Game.win32.exe!AppDelegate::applicationDidFinishLaunching() Line 30 C++
The Method*initWithRawData is here

@ bool CCImage::_initWithRawData(void * pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent) { bool bRet = false; do { CC_BREAK_IF(0 == nWidth || 0 == nHeight); m_nBitsPerComponent = nBitsPerComponent; m_nHeight = (short)nHeight; m_nWidth = (short)nWidth; m_bHasAlpha = true; // only RGBA8888 supported int nBytesPerComponent = 4; int nSize = nHeight * nWidth * nBytesPerComponent; m_pData = new unsigned char[nSize]; CC_BREAK_IF(! m_pData); memcpy(m_pData, pData, nSize); bRet = true; } while (0); return bRet; }

UPDATE2 Found that the issue was due to overlapping addresses. Added below code before mmcpy
if(pData > (m_pData + nSize)) {
CCLOG ("CCImage::_initWithRawData source > dest + size ");
} else {
CCLOG ("CCImage::_initWithRawData error source < dest + size ");
memcpy(m_pData, pData, nSize);
Got output as

CCImage::_initWithRawData error source < dest + size
Is this error because of some problem in my code or is it a bug in Cocos2dx ?_


Anyone knows about this problem? Has no one experienced it?



void AppDelegate::applicationDidEnterBackground()

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()


@Wei-Sung Yeh, thanks for the reply, but sadly its not working.


I realized I was the sending some raw data from android to cocos2dx to create an image sprite. And onPause the raw data was being released from android side, and when cocos2dx was resuming it was not able to find the raw image data at the pointer location and so it was crashing.