My thoughts on error handling, what are yours?
Members - Reputation: 698
Posted 12 May 2013 - 09:03 AM
Crossbones+ - Reputation: 2501
Posted 12 May 2013 - 10:02 AM
What I do in debug/optimised-debug builds is have a glGetError once per frame. If it detects an error, it'll printf it, then flick a switch which enables the 'thorough' testing mode which consists of a glGetError check after every single gl call. The hope is that if there's an error that fires every frame, then I'll get an assert on the problem line, without having the overhead of hundreds of glGetError calls per frame unless something has gone wrong.
In the event that flicking to the thorough mode doesn't catch the error next time around, then I just assert, and typically I'll run again with thorough mode enabled from the getgo.
In final builds I don't do any error checking.
Crossbones+ - Reputation: 5038
Posted 12 May 2013 - 11:00 AM
glGetError may affect your performance (I haven't noticed a significant impact myself, but many people including the authors of OpenGL Insights tell you such) and may at the same time not deliver good enough information to realize immediately what's wrong when doing the "typical" sporadic check.
For that reason, I'm using a debug context during development. You can turn it off by flipping a switch, and it's much more straightforward too (errors are synchronously reported to your callback function as they occur, not when you sporadically poll at some random time later). For a release build, it's California or Bust.
Either your code is correct (correct enough as to not produce errors with a debug context), then it must work, assuming the driver isn't buggy. On the other hand, if the driver is buggy, it probably won't work, but there's nothing you can do about it. You're fighting windmills, so not much point in doing a lot of error checking in release build.
I'm not sure if that approach is the best possible, but it's what I personally think is reasonable.
Edited by samoth, 12 May 2013 - 11:02 AM.
Members - Reputation: 1397
Posted 13 May 2013 - 10:09 AM
gDEBugger and/or CodeXL. Always works. For releases there shouldn't be any errors. However you may still want to look at them each frame.
Stuff I wrote:
Follow me on twitter:
Members - Reputation: 698
Posted 13 May 2013 - 01:19 PM
Thanks for your replies, it's definitely been refreshing to get some new perspective. I'll naturally keep on following the thread (and subforum), and hopefully this proves to be helpful to other people too.
Looks like I've been thinking about how to manage the error handling sprinkled around all the GL code, when it probably could be more constructive to think whether it makes any sense to do it explicitly per command at all or generally how to keep this concern contained in it's own place. No point in extensive checking in release mode, point well taken, but also questionable much it makes sense to keep on following the eight or so relatively vague error codes alone even during development.
The once in a frame checking and runtime toggling of error reporting are things I haven't though of at all and they sound like sensible ways to avoid console or log spamming. When it comes to tools, last night I downloaded CodeXL, and should take a better look at it hopefully soon.