In Cocos2d v3.x, it is not possible to directly invoke the CCDRAWXXX function as in v2.x to draw the geometry.
We can use Ccdrawnode or ccrenderer to draw graphics.
But the official API manual makes it clear that Ccdrawnode is only recommended for debugging in the game, because changing its state must be removed and then re-added, resulting in poor performance when drawing large numbers of complex geometries.
In cocos2d v2.x, direct calls to OpenGL are generally placed in the draw method, but the actual test in v3.4 found that placing the Ccdrawnode draw on draw will cause the app to crash, with the error of not changing the state of the elements in the array when it is traversed.
I guess it's because the drawing nodes in draw will be traversed, including the ccdrawnode we added, but in draw we've modified the Ccdrawnode state so the app crashes.
In a different way, place the Ccdrawnode drawing in the update.
Of course, this is only necessary if the drawing node will change as the game state changes, and if the drawn node is never changed, it can be placed directly into the initialization of the class instance.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Resolving the crash of drawing geometry using Ccdrawnode in cocos2d