Skip to content

Commit

Permalink
Use RAII to always close display at exit.
Browse files Browse the repository at this point in the history
The reason for doing this is that swiftshader debug libraries will
fail with an assertion error if you "leak" objects. This lets us
run with the debug libraries for more comprehensible errors.
  • Loading branch information
DRMacIver committed May 24, 2017
1 parent ffe2673 commit 063eb3b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions get_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ int setUniforms(const GLuint& program, const std::string& fragment_shader) {
return EXIT_SUCCESS;
}

class TerminateEGLAtExit{
EGLDisplay display;

public:
TerminateEGLAtExit(EGLDisplay);
~TerminateEGLAtExit();
};

TerminateEGLAtExit::TerminateEGLAtExit(EGLDisplay display){
this->display = display;
}

TerminateEGLAtExit::~TerminateEGLAtExit(){
auto succeeded = eglTerminate(this->display);
assert(succeeded);
}
/*---------------------------------------------------------------------------*/

int main(int argc, char* argv[]) {
Expand All @@ -349,6 +365,8 @@ int main(int argc, char* argv[]) {
return EXIT_FAILURE;
}

TerminateEGLAtExit cleanup_display = display;

bool persist = false;
bool animate = false;
bool exit_compile = false;
Expand Down

0 comments on commit 063eb3b

Please sign in to comment.