My game crash when i want to destroy my custom drawing sprite

Hello,

i tried to do special sprite, a kind of textured polygon sprite.

the sprite is displayed correctly, but after removed the child sprite, when cocos release the sprite, the app crash when i want destroy the vertices and indices.

here the constructor / destructor :

Some times, the destroy of the array of the vertices is ok and crash when trying to destroy the indices

static SpritePath* create(std::string vSpriteName, CubicSplineTime *vSpline, float vThickNess, int vCountPoints = 10)
    {
        SpritePath *res = 0;
        
        if (vSpriteName.size() > 0 && vSpline != 0 && vThickNess > 0.0f && vCountPoints > 1)
        {
            if (vSpline->GetPoints().size() > 1)
            {
                res = new SpritePath(vSpriteName, vSpline, vThickNess, vCountPoints);
                if (res != 0 && res->init())
                {
                    res->autorelease();
                }
                else
                {
                    CC_SAFE_DELETE(res);
                    res = 0;
                }
            }
        }
        
        return res;
    }

SpritePath(std::string vSpriteName, CubicSplineTime *vSpline, float vThickNess, int vCountPoints) 
        : cocos2d::Sprite(), m_SpriteName(vSpriteName), m_Spline(vSpline), m_CountPoints(vCountPoints),
        m_ThickNess(vThickNess)
    {
        m_Triangles.verts = 0;
        m_Triangles.vertCount = 0;
        m_Triangles.indices = 0;
        m_Triangles.indexCount = 0;
    }
    
    ~SpritePath()
    {
        CC_SAFE_DELETE_ARRAY(m_Triangles.verts);
        CC_SAFE_DELETE_ARRAY(m_Triangles.indices);
    }

i tried before that with the new PolygonInfo but it was the same issue.

and the error message is that :

do you have any ideas of wat is the cause ?

please help me :slight_smile:

what about deleting it another way, i.e not using CC_SAFE_DELETE_ARRAY? Just as a source of troubleshooting/debugging. I don’t know what that macro actually does without looking.

thank for your reply. in fact, im little bit embarassing because, i search in many way to resolve my porblem, because i though it was a problem of destruction of a already released object, but in fact it was a bad writing of the indices of my polygon. i wrote out of the allocated array. so its works now :disappointed_relieved:

we can destroy this topic.its a false flag :slight_smile: