setAccelerometerEnabled crashs CCLayerColor in Android ?

setAccelerometerEnabled crashs CCLayerColor in Android ?
0.0 0

#1

Trying changing CCLayer for CCLayerColor in AccelerometerTest example, get me crashs in android, someone could help me ?


#2

Can you post the code you changed? Original and new.


#3

class AccelerometerTest: public CCLayerColor
{


#4

Looks like the shader program doesn’t get set for CCLayerColor with out calling initWithColor.

If you add

CCSize s = CCDirector::sharedDirector()>getWinSize;
initWithColor, s.width, s.height);
to CCLayer.cpp in the constructor for CCLayerColor
lines 506 and 507 for me but not sure what version you are on - I don’t get a crash anymore.


#5

do you mean:
// cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp

bool CCLayerRGBA::init()
{
if (CCLayer::init())
{
CCSize s = CCDirector::sharedDirector()->getWinSize();

  • initWithColor(ccc4(0,0,0,0), s.width, s.height);
  • *displayedOpacity =*realOpacity = 255;

got some compiling errors

Compile++ thumb : cocos2dx_static <= CCLayer.cpp
/home/joilnen/cocos2d-x/samples/Cpp/Ttt/proj.android/…/…/…/…//cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp: In member function ‘virtual bool cocos2d::CCLayerRGBA::init()’:
/home/joilnen/cocos2d-x/samples/Cpp/Ttt/proj.android/…/…/…/…//cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp:508:55: error: ‘initWithColor’ was not declared in this scope
make: * [obj/local/armeabi/objs/cocos2dx_static/layers_scenes_transitions_nodes/CCLayer.o] Error 1


#6

No. You just need to add them to the CCLayerColor constructor.

CCLayerColor::CCLayerColor()
: m_cOpacity(0)
, m_tColor( ccc3(0,0,0) )
{
// default blend function
m_tBlendFunc.src = CC_BLEND_SRC;
m_tBlendFunc.dst = CC_BLEND_DST;

//add here
}


#7

Thanks, it worked for AccelerometerTest, anyway I am still getting crashs for other codes, is the same to put setAccelemeterEnabled(true) into init or onEnter methods ?