Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

EXC_BAD_ACCESS in Xcode - window not initialized yet?
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=15&t=579
Page 1 of 1

Author:  dkmooers [ Sun Apr 06, 2014 7:37 am ]
Post subject:  EXC_BAD_ACCESS in Xcode - window not initialized yet?

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!

Author:  David Williams [ Mon Apr 07, 2014 8:28 am ]
Post subject:  Re: EXC_BAD_ACCESS in Xcode - window not initialized yet?

I don't have a clear answer to your quetion because I don't really use MacOSX myself, but I think it will make life easier for you if you seperate the three technologies which are at play here. The BasicExample makes use of the folloing:

  • PolyVox (for creating the mesh)
  • OpenGL (for rendering the mesh)
  • Qt (for creating the window and context)

It seems you problem isn't really PolyVox related but is rather OpenGL and/or Qt related. Perhaps CMake is doing some magic setup for you to get this libraries configured correctly, and you may need to reproduce this in XCode?

You should probably put PolyVox aside for a moment and test the tutorials/examples which come with Qt. Several of these demonstrate how to embed OpenGL in Qt, and once this works you can try making your own simple vertex buffer (just rendering a triangle or something). Then after that you an try pulling in the data from PolyVox.

Sorry I can't be more helpful, but breaking the problem down is often the best way to find out what is wrong.

Author:  dkmooers [ Mon Apr 07, 2014 8:23 pm ]
Post subject:  Re: EXC_BAD_ACCESS in Xcode - window not initialized yet?

Thanks David, that's a great answer. I've had some success meantime drawing basic stuff using glew+glfw3 - haven't been able to get meshes from PolyVox to display yet but working on it. I'm getting a better handle of OpenGL and PolyVox in the process. Thanks much!

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/