OCTREE.exe中0x1000bbae处的未处理异常:0xC0000005:访问冲突写入位置0x000000a8 [英] Unhandled exception at 0x1000bbae in OCTREE.exe: 0xC0000005: Access violation writing location 0x000000a8

查看:1485
本文介绍了OCTREE.exe中0x1000bbae处的未处理异常:0xC0000005:访问冲突写入位置0x000000a8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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


推荐答案

7年,所以拿我的答案与一粒盐。这说,你的 init()函数使我有点担心。我相信,当你编写GLUT程序时,你应该只在GLUT回调函数中发出OpenGL命令。当您执行 init()函数时,我不确定是否有活动的OpenGL上下文。如果您删除对 init()

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()?

这篇关于OCTREE.exe中0x1000bbae处的未处理异常:0xC0000005:访问冲突写入位置0x000000a8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆