gpt4 book ai didi

android - cocos2dx 应用程序在恢复 Activity 时崩溃

转载 作者:行者123 更新时间:2023-12-03 17:39:19 24 4
gpt4 key购买 nike

在我的 cocos2dx 游戏中,我正在为结果启动另一个 Activity ,当我返回游戏 Activity 时,它会因以下堆栈而崩溃。通过添加日志,我检查了

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;
}

更新2
发现问题是由于地址重叠造成的。在 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 上崩溃。

最佳答案

我意识到我正在将一些原始数据从 android 发送到 cocos2dx 以创建图像 Sprite 。并且onPause是从android端释放原始数据,当cocos2dx恢复时,它无法在指针位置找到原始图像数据,所以它崩溃了。

关于android - cocos2dx 应用程序在恢复 Activity 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15608978/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com