0000005:在OCTREE.exe 0x1000bbae未处理的异常访问冲突写入位置0x0000

2019-10-30 05:27发布

我得到上线下面的代码上面运行时错误:

glutMainLoop(); 

为什么?

#include <stdio.h>
#include <vector>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cassert>
#include <math.h>
#include <gl/glut.h>
#include <stdlib.h>

class Vertex {

public: float X;
        float Y;
        float Z;

public: Vertex (float first, float second, float third){

            X=first;
            Y=second;
            Z=third;

        }

};


using namespace std;

vector <Vertex> vertexCoordinates;
vector <vector<int>> faces;
vector <vector<float>> faceNormals;
vector <vector<float>> faceCenters;

void loadOff(string inputFileName) {


    int vertexCount; int faceCount; int edgeCount;

    ifstream inputFileStream;

    inputFileStream.open(inputFileName.data());

    assert(inputFileStream.is_open());

    string actualLine;

    inputFileStream>>vertexCount;
    inputFileStream>>faceCount;
    inputFileStream>>edgeCount;


    for (int loadVertexIndex=0; loadVertexIndex<vertexCount; loadVertexIndex++){


        float X;
        float Y;
        float Z;

        inputFileStream>>(float)X;
        inputFileStream>>(float)Y;
        inputFileStream>>(float)Z;

        vertexCoordinates.push_back(Vertex(X,Y,Z));

        if(inputFileStream.eof())break;

    }

    for (int faceIndex=0; faceIndex<=faceCount; faceIndex++){ //<= faceCount?

      string line;

      getline(inputFileStream, line);

      istringstream actualLineStream(line);


      std::vector<int> face((std::istream_iterator<int>(actualLineStream)),
      std::istream_iterator<int>());


      faces.push_back(face);


    }//end for faceCount

}

void display(void) {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);



    glutSwapBuffers();

    glutPostRedisplay();



}


void init(){

    //loadOff("spider.off");

    //BLACK BACKGROUND
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    glEnable(GL_DEPTH_TEST);

    glPolygonMode(GL_BACK, GL_LINE);
    glPolygonMode(GL_FRONT, GL_LINE);

}



void reshape(int w, int h) {


    glViewport (0,0,(GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluLookAt(0.0f, 0.0f, 1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);
    glMatrixMode(GL_MODELVIEW);

}

void keyboard (unsigned char key, int x, int y){

}

void specialKeys(int key, int x, int y) {

}



int main(int argc, char *argv[]){

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
    glutInitWindowSize(800,600);

    init();
    glutDisplayFunc(display);


    glutMainLoop();
    return 0;
}

Answer 1:

我没有用GLUT 7年,所以把我的答案与一粒盐。 这就是说,你init()函数让我有点担心。 我相信,当你写GLUT程序,你应该只在发出过剩回调函数OpenGL命令。 我不知道有当你主动OpenGL上下文init()函数被执行。 方案是否崩溃,如果你删除调用init()



Answer 2:

你得到一个异常试图在0x000000a8写。 正在发生的事情是什么地方你的代码或OpenGL是接收一个空指针,而不是一个有效的指针。 有问题的代码试图更新在从该指针的东西的168(0xa8)所抵消。



文章来源: Unhandled exception at 0x1000bbae in OCTREE.exe: 0xC0000005: Access violation writing location 0x000000a8