sensics / OSVR-RenderManager

Apache License 2.0
64 stars 45 forks source link

OpenGL setup contains non-DRY anti-pattern #164

Closed rpavlik closed 8 years ago

rpavlik commented 8 years ago

Particularly since integration of the toolkit-abstraction code, cleanup on failure is really clouding the setup code. Before it was just removeOpenGLContexts(); that had to be remembered, lest we leak, now there is

if (m_toolkit.removeOpenGLContexts) {
    m_toolkit.removeOpenGLContexts(m_toolkit.data);
}

(which could have easily been placed in a function called removeOpenGLContexts()).

What should probably be in there instead is a finally cleanup object that just gets cancelled in case the function runs all the way to the end successfully: that way it is impossible to leak resources. (I've already found at least one return where we don't release those resources and thus we're leaking...)

russell-taylor commented 8 years ago

Fixed in 7f1f3d8e79a9cfbe05847ec0061b34a02d984c02