diff --git a/common/gal/opengl/utils.cpp b/common/gal/opengl/utils.cpp index bd5312bc34..f484075e48 100644 --- a/common/gal/opengl/utils.cpp +++ b/common/gal/opengl/utils.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2016 CERN + * Copyright (C) 2016-2017 CERN * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -22,14 +22,15 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include +#include // DisplayError #include #include -int checkGlError( const std::string& aInfo ) +int checkGlError( const std::string& aInfo, bool aThrow ) { int result = glGetError(); + wxString errorMsg; switch( result ) { @@ -38,39 +39,45 @@ int checkGlError( const std::string& aInfo ) break; case GL_INVALID_ENUM: - DisplayError( NULL, wxString::Format( "Error: %s: invalid enum", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: invalid enum", aInfo ); break; case GL_INVALID_VALUE: - DisplayError( NULL, wxString::Format( "Error: %s: invalid value", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: invalid value", aInfo ); break; case GL_INVALID_OPERATION: - DisplayError( NULL, wxString::Format( "Error: %s: invalid operation", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: invalid operation", aInfo ); break; case GL_INVALID_FRAMEBUFFER_OPERATION: - DisplayError( NULL, wxString::Format( "Error: %s: invalid framebuffer operation", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: invalid framebuffer operation", aInfo ); break; case GL_OUT_OF_MEMORY: - DisplayError( NULL, wxString::Format( "Error: %s: out of memory", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: out of memory", aInfo ); break; case GL_STACK_UNDERFLOW: - DisplayError( NULL, wxString::Format( "Error: %s: stack underflow", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: stack underflow", aInfo ); break; case GL_STACK_OVERFLOW: - DisplayError( NULL, wxString::Format( "Error: %s: stack overflow", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: stack overflow", aInfo ); break; default: - DisplayError( NULL, wxString::Format( "Error: %s: unknown error", aInfo ) ); + errorMsg = wxString::Format( "Error: %s: unknown error", aInfo ); break; } - //assert( result == GL_NO_ERROR ); + if( result != GL_NO_ERROR ) + { + if( aThrow ) + throw std::runtime_error( errorMsg ); + else + DisplayError( nullptr, errorMsg ); + } return result; } diff --git a/include/gal/opengl/utils.h b/include/gal/opengl/utils.h index 872e932799..2ec901d84c 100644 --- a/include/gal/opengl/utils.h +++ b/include/gal/opengl/utils.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2016 CERN + * Copyright (C) 2016-2017 CERN * @author Maciej Suminski * * This program is free software; you can redistribute it and/or @@ -30,8 +30,10 @@ /** * @brief Checks if one of recent OpenGL operations has failed. If so, it displays appropriate * message, starting with aInfo string to give more details. + * @param aInfo is the beginning of the error message. + * @param aThrow an exception is thrown when true, otherwise only an error message is displayed. * @return GL_NO_ERROR in case of no errors or one of GL_ constants returned by glGetError(). */ -int checkGlError( const std::string& aInfo ); +int checkGlError( const std::string& aInfo, bool aThrow = true ); #endif /* __OPENGL_ERROR_H */