这件事让我发疯了!
我正在尝试使用 Cocos2d (0.99.5) 和 Box2D,并且我已经成功创建了一个包含一个图层和两个物体(实际上是几个弹跳球)的场景。现在我想启用 DebugDrawing,这样我就可以确切地看到正在发生的事情。考虑到在禁用 DebugDrawing 的情况下一切正常。
谈到代码,在我的 init 方法中我有这个:
m_debugDraw = new GLESDebugDraw(PTM_RATIO);
uint32 flags;
flags = 0;
flags += 1 * b2DebugDraw::e_shapeBit;
flags += 1 * b2DebugDraw::e_jointBit;
flags += 1 * b2DebugDraw::e_aabbBit;
flags += 1 * b2DebugDraw::e_pairBit;
flags += 1 * b2DebugDraw::e_centerOfMassBit;
m_debugDraw->SetFlags(flags);
_world->SetDebugDraw(m_debugDraw);
我的绘制方法如下:
-(void)draw {
[super draw];
glDisable(GL_TEXTURE_2D);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
_world->DrawDebugData(); // <------ here comes the problem
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
问题是当程序到达该行时
_world->DrawDebugData();
抛出一个 EXC_BAD_ACCESS 异常。调试器在此处显示错误:
void b2World::DrawDebugData()
{
if (m_debugDraw == NULL)
{
return;
}
uint32 flags = m_debugDraw->GetFlags(); // <----- this is the row pointed by Xcode
if (flags & b2DebugDraw::e_shapeBit)
{
[...]
主窗口显示的错误是:“线程 1:程序接收信号:'EXC_BAD_ACCESS'”。这是我得到的输出:
GNU gdb 6.3.50-20050815(Apple 版本 gdb-1515)(2011 年 1 月 8 日星期六 00:31:48 UTC)版权所有 2004 Free Software Foundation, Inc.
GDB 是自由软件,受 GNU 通用公共许可证保护,欢迎您在特定条件下更改和/或分发它的副本。
键入“显示复制”以查看条件。
GDB 绝对没有任何保证。键入“显示保修”以获取详细信息。
此 GDB 配置为“--host=x86_64-apple-darwin --target=arm-apple-darwin”.tty /dev/ttys000 target remote-mobile /tmp/.XcodeGDBRemote-191-40
切换到 remote-macosx 协议
内存 0x1000 0x3fffffff 缓存
内存 0x40000000 0xffffffff 无
内存 0x00000000 0x0fff 无
[切换到线程 11779]
[切换到线程 11779]
共享库应用加载规则全部
2011-03-03 22:10:36.477 MyApp [2738:707] cocos2d: cocos2d v0.99.5
2011-03-03 22:10:36.529 MyApp [2738:707] cocos2d:使用导演类型:CCDirectorDisplayLink
2011-03-03 22:10:36.936 MyApp [2738:707] cocos2d:操作系统版本:4.3 (0x04030000)
2011-03-03 22:10:36.943 MyApp[2738:707] cocos2d: GL_VENDOR: Imagination Technologies
2011-03-03 22:10:36.949 MyApp[2738:707] cocos2d: GL_RENDERER: PowerVR SGX 535
2011-03-03 22:10:36.956 MyApp [2738:707] cocos2d: GL_VERSION: OpenGL ES-CM 1.1 IMGSGX535-58.1
2011-03-03 22:10:36.966 MyApp[2738:707] cocos2d: GL_MAX_TEXTURE_SIZE: 2048
2011-03-03 22:10:36.973 MyApp[2738:707] cocos2d: GL_MAX_MODELVIEW_STACK_DEPTH: 16
2011-03-03 22:10:36.979 MyApp[2738:707] cocos2d: GL_MAX_SAMPLES: 4
2011-03-03 22:10:37.020 MyApp[2738:707] cocos2d:GL 支持 PVRTC:是
2011-03-03 22:10:37.026 MyApp [2738:707] cocos2d:GL 支持 BGRA8888 纹理:是
2011-03-03 22:10:37.033 MyApp[2738:707] cocos2d:GL 支持 NPOT 纹理:是
2011-03-03 22:10:37.039 MyApp[2738:707] cocos2d: GL 支持discard_framebuffer: 是
2011-03-03 22:10:37.060 MyApp[2738:707] cocos2d:编译时支持 NPOT:否
2011-03-03 22:10:37.066 MyApp [2738:707] cocos2d:在 TextureAtlas 中使用 VBO 支持编译:是
2011-03-03 22:10:37.072 MyApp [2738:707] cocos2d:在 CCNode 中使用仿射矩阵变换编译:是
2011-03-03 22:10:37.078 MyApp [2738:707] cocos2d:编译时使用分析支持:否
2011-03-03 22:10:44.375 MyApp[2738:707] cocos2d:帧间隔:1
2011-03-03 22:10:44.420 MyApp[2738:707] cocos2d:表面尺寸:320x480
2011-03-03 22:10:44.654 MyApp [2738:707] 收到内存警告。等级=1
2011-03-03 22:10:44.696 MyApp [2738:707] cocos2d:解除分配
"MenuBackGround.png", "Star.png", "fps_images.png"
)>
当前语言:自动;目前c++
(gdb)
我试过谷歌搜索,我发现了很多关于这个错误的事情,但我仍然无法解决它。它发生在模拟器和 iPhone 上。在另一个讨论中(对不起,链接丢失)指出这可能与编译器或优化有关,因此我尝试了从 LLVM 切换到 GCC 到 LLVM-GCC 的不同组合,并将优化设置在不同级别,但没有成功。
有人可以指出我正确的方向吗?如果需要更多信息,请告诉我。
谢谢大家,
丹尼尔·萨拉蒂