Month: October 2012

  • Trouble-shooting: Seg-fault (erroneous memory access) on glDrawElements()

    Yesterday, when I was writing basic rendering code for the new ViRe, I keep getting errors of erroneous memory access (in the form of an Ada exception).

    With the small code size I currently have, finding the offending line of source code is a matter of minutes. However, knowing that the exception is raised during the call to glDrawElements(), I still don’t know the cause of it. My first suspect is the Ada OpenGL binding that I have been writing alongside the renderer.

    Today, I wrote a small programme (~100 lines of Ada source text), set up everything that is needed and called glDrawElements(). To my surprise, it worked perfectly. The binding is working fine; it is the code that loads and prepares data that is in fault.

    After some time, I found out that if you call glDrawElements on a VAO that is not ready to be rendered, be it a non-existent array object (including the id 0) or an uninitialised one, a segmentation fault will happen. By uninitialised, I mean the vertex buffer or index buffer is not generated, bind, or you forgot to load data into the index buffer, or you failed to enable the corresponding vertex attribute array, or any combination of them.

    As long as index data is present, its values does not matter. It may cause an empty screen but not a memory access violation. Absence of vertex data does not affect rendering process.

    Note that glDrawArrays() does not generate this error regardless of the circumstances. That makes sense, since it does not rely on index buffer object or index data.

    Development environment:

    • OS: Linux Mint 13 with kernel 3.2.0-30-generic
    • Display Card : NVIDIA GT640M LE
    • Display Card driver: Bumblebee with NVIDIA binary driver 3.0.4.51
  • Back to Square One

    Screen short

    … Or should it be triangle one?

    Result of two months of development and more than 1000 lines of code.

    Most of the code is devoted to the entity system framework. Hope I have time and willingness to write more detail about that when the design stops changing every two days.

    Someone asked me why I find a 24-inch monitor inadequate. This is why. In the picture is only one of my three virtual desktop. When you have to simultaneously edit six or more files, look at 2 thousand-page documents and browse numerous websites, the screen is never big enough.