2013-03-25 165 views
0

從我的cocos2dx遊戲中,我正在爲結果開發另一個acitvity,並且當我返回到遊戲活動時,它與以下堆棧崩潰。通過添加日誌我檢查了cocos2dx應用程序在恢復活動時崩潰

applicationWillEnterForeground() 

CCDirector::sharedDirector()->resume(); 

成功執行,然後應用程序崩潰。類似的,當我按下主頁按鈕暫停應用並重新打開時,行爲會被注意到。但在這種情況下,堆棧跟蹤指向
「/system/lib/egl/libGLESv2_adreno200.so」
文件。

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 [email protected] 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 試圖效仿在Visual Studio中相同的行爲,並調用堆棧上前

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++ 

的方法_initWithRawData在這裏

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 發現問題是由於地址重疊造成的。添加下面的代碼的memcpy

if(pData > (m_pData + nSize)) { 
     CCLOG("CCImage::_initWithRawData source > dest + size "); 
memcpy(m_pData, pData, nSize); 
    } else { 
     CCLOG("CCImage::_initWithRawData error source < dest + size "); 
memmove(m_pData, pData, nSize); 
    } 

了輸出前的

CCImage::_initWithRawData error source < dest + size 

,但應用程序上的memmove仍然會崩潰。

回答

0

我意識到我是從android發送一些原始數據到cocos2dx來創建一個圖像精靈。 onPause原始數據從android端發佈,當cocos2dx恢復時,它無法在指針位置找到原始圖像數據,因此崩潰了。