从我的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 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
更新 试图在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 :(得分:0)
我意识到我是从android向cocos2dx发送一些原始数据来创建一个图像精灵。并且onPause原始数据是从android端发布的,当cocos2dx恢复时,它无法在指针位置找到原始图像数据,因此它崩溃了。