내 프로그램은 실행될 때마다 정확하게 똑같이 수행됩니다 (포인트 스프라이트를 멀리 떨어 뜨리면) 터미널 '불법 명령어'의 텍스트가 무작위로 실패합니다. 내 인터넷 검색은 사람들이 이런 종류의 오류를 throw하기 때문에 사람들이 어셈블리를 작성할 때이 사실을 발견했습니다.리눅스에서 C++ 프로그래밍시 불법 명령어
하지만 왜 g ++가 이와 같이 불법적 인 명령어를 생성합니까? Windows 용으로 컴파일하고 Linux에서 실행하는 것과는 다릅니다 (두 경우 모두 x86에서 AFAIK로 잘못된 명령을 내 보내면 안됩니다). 아래에 주 파일을 게시합니다.
안정적으로 오류를 재현 할 수 없습니다. 비록 무작위적인 변경 (여기에 공간을 추가하고 거기서 상수를 변경)을하면 재 컴파일이 강제 실행됩니다. 중단 점을 설정하려고 할 때까지 불법 명령이 실행될 때마다 실패 할 수있는 바이너리를 얻을 수 있습니다. 불법적 인 지시 'dissapear'. :(
#include <stdio.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#include "Screen.h" //Simple SDL wrapper
#include "Textures.h" //Simple OpenGL texture wrapper
#include "PointSprites.h" //Simple point sprites wrapper
double counter = 0;
/* Here goes our drawing code */
int drawGLScene()
{
/* These are to calculate our fps */
static GLint T0 = 0;
static GLint Frames = 0;
/* Move Left 1.5 Units And Into The Screen 6.0 */
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -6);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glEnable(GL_POINT_SPRITE_ARB);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glBegin(GL_POINTS); /* Drawing Using Triangles */
glVertex3d(0.0,0.0, 0);
glVertex3d(1.0,0.0, 0);
glVertex3d(1.0,1.0, counter);
glVertex3d(0.0,1.0, 0);
glEnd(); /* Finished Drawing The Triangle */
/* Move Right 3 Units */
/* Draw it to the screen */
SDL_GL_SwapBuffers();
/* Gather our frames per second */
Frames++;
{
GLint t = SDL_GetTicks();
if (t - T0 >= 50) {
GLfloat seconds = (t - T0)/1000.0;
GLfloat fps = Frames/seconds;
printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
T0 = t;
Frames = 0;
counter -= .1;
}
}
return 1;
}
GLuint objectID;
int main(int argc, char **argv)
{
Screen screen;
screen.init();
screen.resize(800,600);
LoadBMP("./dist/Debug/GNU-Linux-x86/particle.bmp");
InitPointSprites();
while(true){drawGLScene();}
}
결함이있는 메모리 모듈을 교체하는 것이 좋습니다. – avakar
결함있는 주석 작성자를 바꾸는 것이 좋습니다. –
gdb에서 코드를 실행 한 다음 예외가 발생하면 역 추적 (bt)을 수행합니다. –