[英]Xcode4 and OpenGL - Program received signal: EXC_BAD_ACCESS
I'm making my first steps with OpenGL and Xcode4. 我正在使用OpenGL和Xcode4迈出第一步。 Therefore I created a new Project ( Application -> Command Line Tool -> C++ ).
因此,我创建了一个新项目( 应用程序->命令行工具-> C ++ )。
In the Project I go to Targets -> Build Phases -> Link Binary With Libraries and add two frameworks: OpenGL.framework and GLUT.framework 在项目中,我转到目标->构建阶段->用库链接二进制文件,并添加两个框架: OpenGL.framework和GLUT.framework
This is my main.cpp: 这是我的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;
}
When I run the project the build succeed. 当我运行项目时,构建成功。
But at line glutCreateWindow( "Name_1; Name_2" );
但是在
glutCreateWindow( "Name_1; Name_2" );
Xcode tells me "Thread 1: Program received signal: "EXC_BAD_ACCESS" and it doesn't show up any window. Xcode告诉我“线程1:程序接收到信号:“ EXC_BAD_ACCESS”,它没有显示任何窗口。
Please help me :) thanks! 请帮助我:)谢谢!
[[EDIT]] [[编辑]]
Here is the stacktrace: 这是堆栈跟踪:
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)
I have got this code working on my Macbook Pro (home) and my Fedora 14 PC (work) using the code you have posted (with some minor changes - see below). 我已经使用您发布的代码在Macbook Pro(家用)和Fedora 14 PC(工作)上使用了此代码(做了一些小的更改-参见下文)。 Your problem would appear to be local to you, and not a problem with Glut or your code.
您的问题似乎是本地问题,而不是Glut或代码问题。
This is what it looks like: 看起来是这样的:
Slightly modified code (to clear the window and to enter the main loop): 稍作修改的代码(以清除窗口并进入主循环):
#include <iostream>
#include <stdlib.h>
#include <GLUT/glut.h>
void RenderScene()
{
glLoadIdentity ();
glClear(GL_COLOR_BUFFER_BIT);
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 );
glutMainLoop();
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.