Sprite disappear immediately for an unknown situation involving with every frame updating its z-order

My game involves every frame in updating z-order of characters. So it will sort the visual nicely. Please note that it will update every frame.
The problem kicks in when one of player character just disappears. I’m not sure what’s happening.

I also have several other sprites in the game which also get z-order updating. Most of the time problems start from player character, rarely the less of the time it starts from other sprites.
Code to update its z-order is as follows.

`void Character::reorderSelf()
{
float winHeight = CCDirector::sharedDirector()->getWinSize().height;

this->getParent()->reorderChild(this, winHeight - getPositionY() + CHARACTER_LAYER);
}`

And it’s just run through the loop and call the above function.
Any suggestion or some thoughts to solve the problem?

Hey guys, I’ve fixed the problem. It has nothing to do with cocos2d-x itself. It’s due to kazmath library specifically inside kmVec2Normalize() function which there’s no checking about zero length in which it causes NAN problem.

I added a checking as follows.

`kmVec2* kmVec2Normalize(kmVec2* pOut, const kmVec2* pIn)
{
// prevent NAN result
kmScalar length = kmVec2Length(pIn);
if(length == 0.0f)
length = 1.0f;

kmScalar l = 1.0f / length;

kmVec2 v;
v.x = pIn->x * l;
v.y = pIn->y * l;

pOut->x = v.x;
pOut->y = v.y;

return pOut;

}`

As far as I can tell, it has no problems since then.