在C ++和OpenGL中实现撤消和重做功能时遇到问题

时间:2018-10-11 20:46:00

标签: android c++ opengl-es

am在android上开发交互式图书应用程序,并在c ++和opengl中实现翻页和绘画。对于翻页和绘画笔来说,一切正常,发现问题出在我实现绘画笔的撤消和重做功能时。在我两次撤消或以下一次重做一次后,应用崩溃:

            #include "pencil.h"
            #include "glm.hpp"
            #include "gtc/matrix_transform.hpp"
            #include "gtc/type_ptr.hpp"
            #include "Logger.h"

            #define LOG_TAG "FINGER SHADER"

            using namespace std;
            GLfloat colors[4];
            vector<vector<shared_ptr<mPath>>>MAIN(12);///HOLDS ALL POINTS OF PEN FOR ALL PAGES
            vector<shared_ptr<mPath>> undoMain(0);///HOLDS TEMPORARY POINTS OF A PAGE

            Pen::Pen()
            {
                colors[0] = 1.f;
                colors[1] = 0.f;
                colors[2] = 0.f;
                colors[3] = 1.f;
            path = make_shared<mPath>();
                mx = 0.f;
                my = 0.f;
                PageNo = 0;
            }

            Pen::~Pen()
            {
                undoMain.clear();
                vector<shared_ptr<mPath>>(undoMain.begin(),undoMain.end()).swap(undoMain);
                MAIN.clear();
                vector<vector<shared_ptr<mPath>>>(MAIN.begin(),MAIN.end()).swap(MAIN);
            }

            void Pen::onFingerDown(float x1, float y1)
            {
                undoMain.clear();
              MAIN[PageNo].push_back(path);
                mx = x1;
                my = y1;
                tempPoints.x1=x1;
                tempPoints.y1=y1;
                tempPoints.x2=x1;
                tempPoints.y2=y1;
                path->addVert(tempPoints);
            }

            void Pen::onFingerMove(float x, float y)
            {
                tempPoints.x1=mx;
                tempPoints.y1=my;
                tempPoints.x2=x;
                tempPoints.y2=y;
                path->addVert(tempPoints);
                mx=x;
                 my=y;
            }

            void Pen::onFingerUp()
            {
            path = make_shared<mPath>();
            }

            void Pen::undoPen(){///POINT OF PROBLEM
            if(MAIN[PageNo].size()>0){
                undoMain.push_back(*MAIN[PageNo].erase(MAIN[PageNo].end()-1));
            }
            }

            void Pen::redoPen() {//POINT OF PROBLEM
                if(undoMain.size()>0){
                    MAIN[PageNo].push_back(*undoMain.erase(undoMain.end()-1));
                }
            }

            void Pen::upDatePen(int numb)
            {
                PageNo = numb;
            }

            void Pen::clearUndo() {
                undoMain.clear();
            }

            void Pen::renderLine(const GLuint &program, const glm::mat4 mat)
            {
                GLint perspective=glGetUniformLocation(program,"model");
                glUniformMatrix4fv(perspective,1,GL_FALSE,glm::value_ptr(mat));
                for(auto p:MAIN[PageNo]){
                    for(auto m : p->getPath()){
                        GLint vertex=glGetAttribLocation(program,"vertexPos");
                        GLint colo=glGetUniformLocation(program,"vColor");
                        glEnableVertexAttribArray(vertex);
                        glVertexAttribPointer(vertex,2,GL_FLOAT,GL_FALSE,0,&m);
                        glUniform4fv(colo,1,colors);
                        glLineWidth(30.f);
                        glDrawArrays(GL_LINES,0,2);
                        glDisableVertexAttribArray(vertex);
                    }
                }
            }
            /////////////////////////START OF myPath
            ////////////////////////////////////////////////////////////////////
            mPath::mPath(){}
            ////
            mPath::~mPath() {
                mlineHolder.clear();
            }
            ///
            void mPath::addVert(fingerPos vert)
            {
                mlineHolder.push_back(vert);
            }
            ///
            vector<fingerPos> mPath::getPath()
            {
                return mlineHolder;
            }

0 个答案:

没有答案