Hi.

I want to delete an object after its been selected with a bullet raycast and its color changed - in any order. I create three objects like this. I can delete correctly in order 3-2-1 but in any other order i get a crash because my assignment operator is incorrect.

please help


Code :
vector<Object> allObj;
 
grid = new Object(*this);
grid->rename("grid", myEtc->allObj); grid->type->val_s = "grid";
grid->t->val_3 = glm::vec3(-3.f, 0.f, 0.f);
myEtc->allObj.push_back(*grid);
delete grid;

Code :
 
void MainWindow::deleteItem()
{
    for (vector<Object>::iterator iter = myEtc->allObj.begin(); iter != myEtc->allObj.end();)
    {
        if ((*iter).highlight == myGLHelp->highlight)
        {
            (*iter).delete_();
            iter = myEtc->allObj.erase(iter);
            break;
        }
 
        else
            ++iter;
    }
 
    myGL->updateGL();
}

Code :
class Object
{
public:
    MainWindow &myWin;
    Object(MainWindow &);
    Object(const Object &);
    Object& operator=(const Object &obj);
 
    ~Object() { };
    virtual Object* clone() const { return new Object( *this ); }
 
    vector<MatrixAttr*> keyable;
    vector<MatrixAttr*> nonkeyable;
    MatrixAttr *name, *t, *r, *s, *v;
    MatrixAttr *camType, *fov, *lookAt, *nearClip, *farClip;
    MatrixAttr *expand, *mode, *parent, *rotOrder, *type, *piv_r, *piv_t;
    glm::quat r_quat;
 
    btCollisionShape *boxCollisionShape;
    btRigidBody *rigidBody;
    float bbMin_x, bbMin_y, bbMin_z, bbMax_x, bbMax_y, bbMax_z;
    glm::vec3 bbCenter, bbSize, bbSizeFull;
    glm::vec4 highlight;
 
    //GRID
    bool loadedVaoVbo, preExist;
    int gridLines, gridLines_;
    float gridMinus_, gridMinus;
    string gridColor;
    vector<TwoVecs> gridVerts;
    vector<glm::vec3> gridVertsH, gridVertsV;
 
    btTransform bbXform;
    glm::mat4 MVP, ModelM, translationM, rotationM, scaleM;
    glm::mat4 transLocal1M, transLocal2M, localSpaceM;
    glm::mat4 bbScaleM, bbRotationM, bbTranslationM, bbMVP;
 
    glm::mat4 firstRotOrder, secondRotOrder, thirdRotOrder;
    glm::mat4 bbM;
    string order, order0, order1, order2;
 
    //matrix
    GLuint shaderID, MatrixID, isSelectedID, vao_grid1, vao_grid2, vbo_grid1, vbo_grid2, vao_bb, vbo_bbV, vbo_bbI;
private:
};


Code :
Object & Object::operator=(const Object &obj) //ASSIGNMENT CONSTRUCTOR
{
    if (this == &obj) // Check for self assignment
      return *this;
 
    keyable.resize(obj.keyable.size());
    nonkeyable.resize(obj.nonkeyable.size());
 
    for (int i = 0; i < obj.keyable.size(); ++i)
    {
        keyable[i] = obj.keyable[i]->clone();
 
        if (keyable[i]->name == obj.keyable[i]->name)
        {
            if (keyable[i]->name == "name")
                name = keyable[i];
            else if (keyable[i]->name == "t")
                t = keyable[i];
            else if (keyable[i]->name == "r")
                r = keyable[i];
            else if (keyable[i]->name == "s")
                s = keyable[i];
            else if (keyable[i]->name == "v")
                v = keyable[i];
 
            //cam
            else if (keyable[i]->name == "camType")
                camType = keyable[i];
            else if (keyable[i]->name == "fov")
                fov = keyable[i];
            else if (keyable[i]->name == "lookAt")
                lookAt = keyable[i];
            else if (keyable[i]->name == "nearClip")
                nearClip = keyable[i];
            else if (keyable[i]->name == "farClip")
                farClip = keyable[i];
        }
    }
 
    for (int i = 0; i < obj.nonkeyable.size(); ++i)
    {
        nonkeyable[i] = obj.nonkeyable[i]->clone();
 
        if (nonkeyable[i]->name == "name")
            name = nonkeyable[i];
        else if (nonkeyable[i]->name == "expand")
            expand = nonkeyable[i];
        else if (nonkeyable[i]->name == "mode")
            mode = nonkeyable[i];
        else if (nonkeyable[i]->name == "parent")
            parent = nonkeyable[i];
        else if (nonkeyable[i]->name == "rotOrder")
            rotOrder = nonkeyable[i];
        else if (nonkeyable[i]->name == "type")
            type = nonkeyable[i];
        else if (nonkeyable[i]->name == "piv_r")
            piv_r = nonkeyable[i];
        else if (nonkeyable[i]->name == "piv_t")
            piv_t = nonkeyable[i];
    }
 
    r_quat = obj.r_quat;
    *boxCollisionShape = *obj.boxCollisionShape;
    *rigidBody = *obj.rigidBody;
    bbMin_x = obj.bbMin_x; bbMin_y = obj.bbMin_y; bbMin_z = obj.bbMin_z;
    bbMax_x = obj.bbMax_x; bbMax_y = obj.bbMax_y; bbMax_z = obj.bbMax_z;
    bbCenter = obj.bbCenter; bbSize = obj.bbSize; bbSizeFull = obj.bbSizeFull;
    highlight = obj.highlight;
 
    loadedVaoVbo = 0;
    preExist = obj.preExist;
    gridLines = obj.gridLines; gridLines_ = obj.gridLines_;
    gridMinus_ = obj.gridMinus_; gridMinus = obj.gridMinus;
    gridColor = obj.gridColor;
 
    gridVerts.resize(0);
    gridVertsH.resize(0);
    gridVertsV.resize(0);
 
    bbXform = obj.bbXform;
    MVP = obj.MVP; ModelM = obj.ModelM; translationM = obj.translationM; rotationM = obj.MVP; MVP = obj.rotationM; scaleM = obj.scaleM;
    transLocal1M = obj.transLocal1M; transLocal2M = obj.transLocal2M; localSpaceM = obj.localSpaceM;
    bbScaleM = obj.bbScaleM; bbRotationM = obj.bbRotationM; bbTranslationM = obj.bbTranslationM; bbMVP = obj.bbMVP;
 
    firstRotOrder = obj.firstRotOrder; secondRotOrder = obj.secondRotOrder; thirdRotOrder = obj.thirdRotOrder;
 
    bbM = obj.bbM;
    order = obj.order; order0 = obj.order0; order1 = obj.order1; order2 = obj.order2;
 
    shaderID = obj.shaderID; MatrixID = obj.MatrixID; isSelectedID = obj.isSelectedID;
    vao_grid1 = obj.vao_grid1; vao_grid2 = obj.vao_grid2; vbo_grid1 = obj.vbo_grid1; vbo_grid2 = obj.vbo_grid2;
    vao_bb = obj.vao_bb; vbo_bbV = obj.vbo_bbV; vbo_bbI = obj.vbo_bbI;
 
 
    return *this;
}

Code :
void Object::delete_()
{
    if (type->val_s == "grid")
    {
        glUseProgram(NULL);
        glDeleteProgram(this->shaderID);
        myWin.myGLHelp->handleError("Couldnt delete shaders", "gl");
 
        glBindVertexArray(0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
        glDeleteVertexArrays(1, &vao_grid1);
        glDeleteVertexArrays(1, &vao_grid2);
        glDeleteVertexArrays(1, &vao_bb);
//        myWin.myGLHelp->handleError("Couldnt delete VAO", "gl");
 
        glDisableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
 
        glDeleteBuffers(1, &vbo_grid1);
        glDeleteBuffers(1, &vbo_grid2);
        glDeleteBuffers(1, &vbo_bbV);
        glDeleteBuffers(1, &vbo_bbI);
//        myWin.myGLHelp->handleError("Couldnt delete VBO", "gl");
    }
 
//    //CLEAN UP BULLET
    myWin.myEtc->bulletDynW->removeRigidBody(rigidBody);
    delete rigidBody->getMotionState();
    delete rigidBody;
    delete boxCollisionShape;
 
//        myWin.myGLHelp->handleError("Couldnt delete properly", "gl");
}