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

跟風遠走 提交于 2020-01-06 05:46:29

问题


I'm getting the above runtime error on the following code on line:

glutMainLoop(); 

Why?

#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;
}

回答1:


I have not used GLUT for 7 years, so take my answer with a grain of salt. This said, your init() function makes me a bit concerned. I believe that when you write GLUT programs, you should only issue OpenGL commands in the GLUT callback functions. I'm not sure there is an active OpenGL context when your init() function is executed. Does the program crash if you remove the call to init()?




回答2:


You are getting an exception trying to write at 0x000000a8. What is happening is that somewhere your code or the openGL is receiving a null pointer rather than a valid pointer. The code in question is trying to update something at an offset of 168 (0xa8) from that pointer.



来源:https://stackoverflow.com/questions/6178693/unhandled-exception-at-0x1000bbae-in-octree-exe-0xc0000005-access-violation-wr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!