My code not error, but my game force close

MainScene.cpp (2.0 KB)
MainScene.h (389 Bytes)

    //This is Error??
DrawNode *rects;
Vec2 vert[4];
vert[0] = Vec2(origin.x , origin.y + visibleSize.height / 2);
vert[1] = Vec2(origin.x , origin.y + visibleSize.height);
vert[2] = Vec2(origin.x + visibleSize.width, origin.y + visibleSize.height);
vert[3] = Vec2(origin.x + visibleSize.width, origin.y + visibleSize.height / 2 );
Color4B warna = Color4B(38,50,56,255);
Color4F aa = Color4F(Color4B(warna));
rects -> drawPolygon(vert, 4, aa, 1, aa);
this -> addChild(rects, 1);
////////////////////////////////////////////////////////////////////////////////////

Please check my code. i think the error is from rects / draw polygon. i am using cocos2dx 3.16. Thank you

hey man
please give us some kinda logs and stuff , just part of your code won’t help that much without error logs.

how about this maybe :

auto rects = DrawNode::create();

-michio

2 Likes

Thank you for respond my question. Btw, I have uploaded my cpp. Can you run that?

your welcome mate ,

i changed DrawNode *rects; to auto rects = DrawNode::create();

and the result is in the image , i built the win.10 project.

oh, it works! thank you :smile: