this thing is making me crazy!
I'm experimenting with Cocos2d (0.99.5) and Box2D, and I have successfully created a scene with a layer and two bodies (actually a couple of bouncing balls). Now I would like to enable the DebugDrawing so I can see exactly what is happening. Consider that everything works with DebugDrawing disabled.
Talking about the code, in my init method I have this:
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);
My draw method is as follows:
-(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);
}
The problem is that when the program reaches the line
_world->DrawDebugData();
an EXC_BAD_ACCESS exception in thrown. The debugger shows the error here:
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)
{
[...]
The error shown on the main window is: "Thread 1: Program received signal: 'EXC_BAD_ACCESS'". This is the output I get:
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 8 00:31:48 UTC 2011) Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin --target=arm-apple-darwin".tty /dev/ttys000 target remote-mobile /tmp/.XcodeGDBRemote-191-40
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
[Switching to thread 11779]
[Switching to thread 11779]
sharedlibrary apply-load-rules all
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: Using Director Type:CCDirectorDisplayLink
2011-03-03 22:10:36.936 MyApp[2738:707] cocos2d: OS version: 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 supports PVRTC: YES
2011-03-03 22:10:37.026 MyApp[2738:707] cocos2d: GL supports BGRA8888 textures: YES
2011-03-03 22:10:37.033 MyApp[2738:707] cocos2d: GL supports NPOT textures: YES
2011-03-03 22:10:37.039 MyApp[2738:707] cocos2d: GL supports discard_framebuffer: YES
2011-03-03 22:10:37.060 MyApp[2738:707] cocos2d: compiled with NPOT support: NO
2011-03-03 22:10:37.066 MyApp[2738:707] cocos2d: compiled with VBO support in TextureAtlas : YES
2011-03-03 22:10:37.072 MyApp[2738:707] cocos2d: compiled with Affine Matrix transformation in CCNode : YES
2011-03-03 22:10:37.078 MyApp[2738:707] cocos2d: compiled with Profiling Support: NO
2011-03-03 22:10:44.375 MyApp[2738:707] cocos2d: Frame interval: 1
2011-03-03 22:10:44.420 MyApp[2738:707] cocos2d: surface size: 320x480
2011-03-03 22:10:44.654 MyApp[2738:707] Received memory warning. Level=1
2011-03-03 22:10:44.696 MyApp[2738:707] cocos2d: deallocing
"MenuBackGround.png", "Star.png", "fps_images.png"
)>
Current language: auto; currently c++
(gdb)
I have tried googling and I found out a lot of things about this error, still I can't solve it. It happens both on the simulator and on the iPhone. Someone on another discussion (sorry, lost the link) pointed out that it may be related to the compiler or the optimization, thus I tried different combinations switching from LLVM to GCC to LLVM-GCC and setting the optimization at different levels with no success.
Can someone point me in the right direction? Let me know if more information is needed.
Thanks you all,
Daniele Salatti