I'm very new to graphics / OpenGL programming, and am digging into PolyVox for building my own smooth-voxel forest game, but I'm having some growing pains!
I was able to build and run the "Basic" example on OS X Mavericks, with no errors (displayed the sphere of voxels properly in a window), but when I copied the code from that example into an Xcode project, I get an error. I'm able to build successfully, but when I run it, I get an "EXC_BAD_ACCESS" error.
It occurs in OpenGLWidget::paintGL() - specifically, in this line:
Code:
glDrawRangeElements(GL_TRIANGLES, m_uBeginIndex, m_uEndIndex-1, m_uEndIndex - m_uBeginIndex, GL_UNSIGNED_INT, 0);
The error says "Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)".
Seems like a null pointer error? After doing some reading, I found the suggestion that this error can occur if you make draw calls before you've set up an OpenGL context. However, I just copied the code from the Basic example, so it seems like it should work... I figured these lines in main.cpp set up the context/window:
Code:
QApplication app(argc, argv);
OpenGLWidget openGLWidget(0);
openGLWidget.show();
The bizarre thing is, if I comment out that "glDrawRangeElements" line, a black window pops up with no error. Also, with that line still commented out, if I set a breakpoint on it and run the code, it gets to this glDrawRangeElements line before a black window has popped up yet. After I play through the breakpoint, the empty black window shows up. So it really does seem like the window hasn't been initialized yet!
Here's a few lines from main.cpp:
Code:
//Create and show the Qt OpenGL window
QApplication app(argc, argv);
OpenGLWidget openGLWidget(0);
openGLWidget.show();
So it looks like the last line triggers OpenGLWidget::initializeGL(), which works fine, and then goes on to run OpenGLWidget::paintGL(), which triggers the error because the window hasn't appeared yet, I'm guessing?
Any ideas on how to fix this? I'm scratching my head as to why the Basic example compiled and ran fine on my machine (using CMake), but when I copied the exact code / files into Xcode I get this error.
Also, in the bit of code that spits out "OpenGL Implementation Details," here's what I get (I'm on a new Mac Pro):
Quote:
OpenGL Implementation Details:
GL_VENDOR: ATI Technologies Inc.
GL_RENDERER: AMD Radeon HD - FirePro D700 OpenGL Engine
GL_VERSION: 2.1 ATI-1.20.11
GL_SHADING_LANGUAGE_VERSION: 1.20
Mavericks supports OpenGL 4.1 - so shouldn't that GL_VERSION be 4.1? Why is it 2.1? Or maybe it's running in compatibility profile instead of core profile, which is why it's regressing to 2.1 instead of 4.1? (When I run OpenGL Extensions Viewer, it says my system has 4.1 when I select "core", but 2.1 when I select compatibility".) I'm wondering if this is related to the EXC_BAD_ACCESS error or totally separate.
Would much appreciate any tips on this!