我正在開發OpenGL和Xcode4的第一步。 因此我創建了一個新的項目(應用程序 - >命令行工具 - > C++)。Xcode4和OpenGL - 編程接收信號:EXC_BAD_ACCESS
在項目我去目標 - >構建階段 - >鏈接二進制與圖書館並添加兩個框架:OpenGL.framework和GLUT.framework
這是我的main.cpp:
#include <iostream>
#include <stdlib.h>
#include <GLUT/glut.h>
void RenderScene()
{
glLoadIdentity();
glBegin(GL_POLYGON);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertex3f(-0.5, -0.5, -0.5);
glVertex3f( 0.5, -0.5, -0.5);
glVertex3f( 0.5, 0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutCreateWindow("Name_1; Name_2");
glutDisplayFunc(RenderScene);
return 0;
}
當我運行項目時,構建成功。
,但在行glutCreateWindow("Name_1; Name_2");
的Xcode告訴我「主題1:程序接收到的信號: 「EXC_BAD_ACCESS」,並沒有出現任何的窗口
請幫我:)謝謝
[!編輯]
這裏是堆棧跟蹤:
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
[Switching to process 7126 thread 0x0]
2011-03-30 16:14:45.052 OpenGL[7126:903] NSSoftLinking - The function 'CGLSetOption' can't be found in the OpenGL framework.
sharedlibrary apply-load-rules all
Current language: auto; currently c++
(gdb) where
#0 0x0000000000000000 in ??()
#1 0x00007fff815efb43 in createPixelFormat()
#2 0x00007fff815efae9 in -[NSOpenGLPixelFormat initWithAttributes:]()
#3 0x000000010001bad3 in createPixelFormat()
#4 0x000000010001b251 in __glutDeterminePixelFormat()
#5 0x000000010001b3f7 in __glutCreateWindow()
#6 0x000000010001b7bd in glutCreateWindow()
#7 0x0000000100000d2b in main (argc=1, argv=0x7fff5fbff6e8) at /Users/.../main.cpp:23
Current language: auto; currently c++
(gdb)
請出示從gdb的堆棧跟蹤。 – trojanfoe 2011-03-30 13:54:07
順便說一下:我添加了'glutMainLoop()'到最後,並在Linux下嘗試了它,它工作得很好(使用freeglut),所以它基本上可以。 – trojanfoe 2011-03-30 14:03:02
對不起,我在哪裏可以找到gdb的stacktrace? – Christoph 2011-03-30 14:09:25