|
c++로 opengl 이용해 삼각형 그리는 프로그램 만드는데 컴파일에러가 없는데 프로그램을 돌릴라 치면 디버그 에러가 뜹니다.
Unhandled exception at 0x00FC574E in ConsoleApplication2.exe: 0xC0000005: Access violation reading location 0x00000000.
이런 디버그에러가뜨는데요 구글링해보니까 포인터 초기화관련문제라는데
어디가 문제인지 모르겠습니다
밑에가 제가 쓴 메인코드입니다.
#include<iostream>
#include<fstream>
#include"triangle.h"
#include<GL/glut.h>
//implement here - include header files
float** position; //data to save vertices position.
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1, 1, 1, 1);
glBegin(GL_TRIANGLES);
glVertex3f(position[0][0], position[0][1], position[0][2]);
glVertex3f(position[1][0], position[1][1], position[1][2]);
glVertex3f(position[2][0], position[2][1], position[2][2]);
glEnd();
//implement here - draw triangle,
glutSwapBuffers();
}
void main(int argc, char **argv) {
int m = 3, n = 3;
float** position = new float*[m];
for (int i = 0; i < m; ++i){
position[i] = new float[n];
}
//implement here - position is 3x3 array, allocate the memory.
readFile(position);
for (int i = 0; i < n; ++i)
delete[]position[i];
delete[]position; // init GLUT and create Window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100, 100);
glutInitWindowSize(320, 320);
glutCreateWindow("practice_03!");
// register callbacks
glutDisplayFunc(renderScene);
// enter GLUT event processing cycle
glutMainLoop();
}
이건 헤더파일입니다.
#ifndef _triangle_h
#define _triangle_h
void readFile(float** inputlist);
#endif _triangle_h
이 파일은 파일 출력하기 위해 만든 소스입니다.
#include<fstream>
#include"triangle.h"
void readFile(float** inputlist){
std::ifstream ifs("input.txt");
}
메인 소스 어디가 문제가 생겨서 debug오류가 자꾸생길까요???
|