EXC_BAD_ACCESS error in GetAngle() in cocos2dx samples

General discussion about the R.U.B.E editor
Post Reply
barisatamer
Posts: 3
Joined: Thu Jan 16, 2014 5:15 pm

EXC_BAD_ACCESS error in GetAngle() in cocos2dx samples

Post by barisatamer »

I've created a new project with cocos2d-x-3.0alpha0 and added the files in rube-cocos2d-x-sample-project-src.zip

The reload button in sample layers (Images load, Pinball demo, PlanetCute demo, which use images) works fine in Simulator.
However, when running on iPad, if I hit the Reload button in the scene, I get a EXC_BAD_ACCESS error in GetAngle() method.

Code: Select all

inline float32 b2Body::GetAngle() const
{
	return m_sweep.a; // Thread 1: EXC_BAD_ACCESS (code=1, address=0x12d4c18)
}
Is this a bug ? What can I do to solve this ?
Any help would be appreciated.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: EXC_BAD_ACCESS error in GetAngle() in cocos2dx samples

Post by iforce2d »

So the scene loads correctly one time, but the 'reload' button does causes a crash? Seems odd. Are there any messages in the debug log output? What happens if you do 'back' and then load the scene again instead of 'reload'?

The code you have posted is part of Box2D and just means that the body pointer that GetAngle is being called on is invalid. It could be NULL, or a pointer that was not initialized correctly, or has been deleted.

You can use the debugger to step through the loading process in afterLoadProcessing and keep an eye out for something going wrong.
barisatamer
Posts: 3
Joined: Thu Jan 16, 2014 5:15 pm

Re: EXC_BAD_ACCESS error in GetAngle() in cocos2dx samples

Post by barisatamer »

I tried calling GetPosition(), GetMass() methods in RUBELayer::setImagePositionsFromPhysicsBodies() and they all resulted the same error.

I think the reason was that the body variable in RubeImageInfo m_imageInfos was not initialized correctly.

I tried clearing the m_imageInfos set in RUBELayer::clear method. And it works now without any errors.

Code: Select all

void RUBELayer::clear()
{
    for (set<RUBEImageInfo*>::iterator it = m_imageInfos.begin(); it != m_imageInfos.end(); ++it) {
        RUBEImageInfo* imgInfo = *it;
        removeChild(imgInfo->sprite, true);
    }
    
    m_imageInfos.clear();
    
    BasicRUBELayer::clear();
}
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: EXC_BAD_ACCESS error in GetAngle() in cocos2dx samples

Post by iforce2d »

You are quite correct, thanks for the fix!

I cannot imagine why this never showed up as a problem for me on 3 iOS devices and all my Android ones, or why it was ok in the simulator for you. Oh well... it's solved now I suppose :)
Post Reply