Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
hexc11196yI guess I should also mention, I'm not a massive fan of having to instantiate a stack object and create a generic lambda wrapper for every GL call just to exploit the objects destructor as sort of "onGLCallFinished" callback. Is there a better/cleaner way of setting up this type of behavior?
-
hexc11196yBeen messing around with a more generic solution that might be useful elsewhere. Still has the issue as mentioned in the original post though. Also in this example you cannot use any local variables within the ON_EXIT_SCOPE block... Though I think this can be worked around pretty easily. Still looking for any better ways of doing something like this though...
-
hexc11196yHere is an example that now supports using external variables internally. Kinda weird to think about considering I'm modifying a variable within a function after the the return statement is called, but before it actually exits...🤔
-
@hexc how do you know the destructor for your logger is running before any other variables in scope? Can't a's destructor get called before you modify it? Since it's a function argument I doubt this is ever the case, but could it be true for other variables?
-
Polarina1206yThere's an extension for this, GL_KHR_debug. You register a callback and the driver will call it for each error it encounters.
-
hexc11196y@Polarina yeah, I had seen that, it's probably the way I'll go. I just thought this was an interesting exercise to go through being that it's more general purpose. And thought ide share my discoveries. Also if I'm not mistaken, the callback is an extension method not available on all platforms. Was thinking this could be a fallback in those situations.
Related Rants
-
Dacexi24When there are only 2 pages on Google you know you're in serious shit.
-
practiseSafeHex20Fixing a parents iPhone, episode 1. Problem: "Whatsapp is gone off my phone" Debugging: Me: *unlocks phone...
-
nachocode6When you talk to other devs about what their code did. I also relate myself to this.
So I'm doing some OpenGL stuff in C++, for debugging I've created a macro that basically injects my error check code after every OpenGL API call. Basically I don't want any of the code in release builds but I want it to be in debug. Also it needs to be usable inline and accept any GL function return type. From what I can tell I've satisfied all requirements by making the macro generate a generic lambda that returns the original function call result but also creates a stack object that uses the scope to force my error check after the return statement by using the destructor.
Basically I can do:
Log(gl(GetString(...));
gl(DeleteShader(...));
Etc where the GL call can be a function parameter or not.
So my question is, is the code shown in the picture the best way to achieve my goals while providing the behaviour im going for?
question
cpp
macros
debugging