From a6f963ec4ac484b1385456aa445d6c66feb0b0b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 22 Nov 2012 15:08:48 +0100 Subject: [PATCH] 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 --- scene_opengl.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index b27fb3a01c..03a31cf92d 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -145,10 +145,11 @@ void OpenGLBackend::idle() SceneOpenGL::SceneOpenGL(Workspace* ws, OpenGLBackend *backend) : Scene(ws) - , init_ok(false) + , init_ok(true) , m_backend(backend) { if (m_backend->isFailed()) { + init_ok = false; return; } @@ -158,11 +159,13 @@ SceneOpenGL::SceneOpenGL(Workspace* ws, OpenGLBackend *backend) if (!hasGLExtension("GL_ARB_texture_non_power_of_two") && !hasGLExtension("GL_ARB_texture_rectangle")) { kError(1212) << "GL_ARB_texture_non_power_of_two and GL_ARB_texture_rectangle missing"; + init_ok = false; return; // error } #endif if (glPlatform->isMesaDriver() && glPlatform->mesaVersion() < kVersionNumber(8, 0)) { kError(1212) << "KWin requires at least Mesa 8.0 for OpenGL compositing."; + init_ok = false; return; } #ifndef KWIN_HAVE_OPENGLES @@ -472,6 +475,10 @@ SceneOpenGL2::SceneOpenGL2(OpenGLBackend *backend) : SceneOpenGL(Workspace::self(), backend) , m_colorCorrection(new ColorCorrection(this)) { + if (!init_ok) { + // base ctor already failed + return; + } // Initialize color correction before the shaders kDebug(1212) << "Color correction:" << options->isColorCorrected(); m_colorCorrection->setEnabled(options->isColorCorrected()); @@ -480,6 +487,7 @@ SceneOpenGL2::SceneOpenGL2(OpenGLBackend *backend) if (!ShaderManager::instance()->isValid()) { kDebug(1212) << "No Scene Shaders available"; + init_ok = false; return; } @@ -487,11 +495,10 @@ SceneOpenGL2::SceneOpenGL2(OpenGLBackend *backend) ShaderManager::instance()->pushShader(ShaderManager::SimpleShader); if (checkGLError("Init")) { kError(1212) << "OpenGL 2 compositing setup failed"; + init_ok = false; return; // error } kDebug(1212) << "OpenGL 2 compositing successfully initialized"; - - init_ok = true; } SceneOpenGL2::~SceneOpenGL2() @@ -599,15 +606,19 @@ SceneOpenGL1::SceneOpenGL1(OpenGLBackend *backend) : SceneOpenGL(Workspace::self(), backend) , m_resetModelViewProjectionMatrix(true) { + if (!init_ok) { + // base ctor already failed + return; + } ShaderManager::disable(); setupModelViewProjectionMatrix(); if (checkGLError("Init")) { kError(1212) << "OpenGL 1 compositing setup failed"; + init_ok = false; return; // error } kDebug(1212) << "OpenGL 1 compositing successfully initialized"; - init_ok = true; } SceneOpenGL1::~SceneOpenGL1()