Invert logic of init_ok in SceneOpenGL

In case that one of the checks in SceneOpenGL failed the ctor of the
sub-class continued and set init_ok to true although it should have been
set to false.

Now init_ok starts with true and if a check fails it is set to false.
For 4.11 we should consider using an exception here - variables to check
that init code works are just no proper solution.

REVIEW: 107420
This commit is contained in:
Martin Gräßlin 2012-11-22 15:08:48 +01:00
parent bcfc0269ae
commit a6f963ec4a

View file

@ -145,10 +145,11 @@ void OpenGLBackend::idle()
SceneOpenGL::SceneOpenGL(Workspace* ws, OpenGLBackend *backend) SceneOpenGL::SceneOpenGL(Workspace* ws, OpenGLBackend *backend)
: Scene(ws) : Scene(ws)
, init_ok(false) , init_ok(true)
, m_backend(backend) , m_backend(backend)
{ {
if (m_backend->isFailed()) { if (m_backend->isFailed()) {
init_ok = false;
return; return;
} }
@ -158,11 +159,13 @@ SceneOpenGL::SceneOpenGL(Workspace* ws, OpenGLBackend *backend)
if (!hasGLExtension("GL_ARB_texture_non_power_of_two") if (!hasGLExtension("GL_ARB_texture_non_power_of_two")
&& !hasGLExtension("GL_ARB_texture_rectangle")) { && !hasGLExtension("GL_ARB_texture_rectangle")) {
kError(1212) << "GL_ARB_texture_non_power_of_two and GL_ARB_texture_rectangle missing"; kError(1212) << "GL_ARB_texture_non_power_of_two and GL_ARB_texture_rectangle missing";
init_ok = false;
return; // error return; // error
} }
#endif #endif
if (glPlatform->isMesaDriver() && glPlatform->mesaVersion() < kVersionNumber(8, 0)) { if (glPlatform->isMesaDriver() && glPlatform->mesaVersion() < kVersionNumber(8, 0)) {
kError(1212) << "KWin requires at least Mesa 8.0 for OpenGL compositing."; kError(1212) << "KWin requires at least Mesa 8.0 for OpenGL compositing.";
init_ok = false;
return; return;
} }
#ifndef KWIN_HAVE_OPENGLES #ifndef KWIN_HAVE_OPENGLES
@ -472,6 +475,10 @@ SceneOpenGL2::SceneOpenGL2(OpenGLBackend *backend)
: SceneOpenGL(Workspace::self(), backend) : SceneOpenGL(Workspace::self(), backend)
, m_colorCorrection(new ColorCorrection(this)) , m_colorCorrection(new ColorCorrection(this))
{ {
if (!init_ok) {
// base ctor already failed
return;
}
// Initialize color correction before the shaders // Initialize color correction before the shaders
kDebug(1212) << "Color correction:" << options->isColorCorrected(); kDebug(1212) << "Color correction:" << options->isColorCorrected();
m_colorCorrection->setEnabled(options->isColorCorrected()); m_colorCorrection->setEnabled(options->isColorCorrected());
@ -480,6 +487,7 @@ SceneOpenGL2::SceneOpenGL2(OpenGLBackend *backend)
if (!ShaderManager::instance()->isValid()) { if (!ShaderManager::instance()->isValid()) {
kDebug(1212) << "No Scene Shaders available"; kDebug(1212) << "No Scene Shaders available";
init_ok = false;
return; return;
} }
@ -487,11 +495,10 @@ SceneOpenGL2::SceneOpenGL2(OpenGLBackend *backend)
ShaderManager::instance()->pushShader(ShaderManager::SimpleShader); ShaderManager::instance()->pushShader(ShaderManager::SimpleShader);
if (checkGLError("Init")) { if (checkGLError("Init")) {
kError(1212) << "OpenGL 2 compositing setup failed"; kError(1212) << "OpenGL 2 compositing setup failed";
init_ok = false;
return; // error return; // error
} }
kDebug(1212) << "OpenGL 2 compositing successfully initialized"; kDebug(1212) << "OpenGL 2 compositing successfully initialized";
init_ok = true;
} }
SceneOpenGL2::~SceneOpenGL2() SceneOpenGL2::~SceneOpenGL2()
@ -599,15 +606,19 @@ SceneOpenGL1::SceneOpenGL1(OpenGLBackend *backend)
: SceneOpenGL(Workspace::self(), backend) : SceneOpenGL(Workspace::self(), backend)
, m_resetModelViewProjectionMatrix(true) , m_resetModelViewProjectionMatrix(true)
{ {
if (!init_ok) {
// base ctor already failed
return;
}
ShaderManager::disable(); ShaderManager::disable();
setupModelViewProjectionMatrix(); setupModelViewProjectionMatrix();
if (checkGLError("Init")) { if (checkGLError("Init")) {
kError(1212) << "OpenGL 1 compositing setup failed"; kError(1212) << "OpenGL 1 compositing setup failed";
init_ok = false;
return; // error return; // error
} }
kDebug(1212) << "OpenGL 1 compositing successfully initialized"; kDebug(1212) << "OpenGL 1 compositing successfully initialized";
init_ok = true;
} }
SceneOpenGL1::~SceneOpenGL1() SceneOpenGL1::~SceneOpenGL1()