From a8f73821cae207e989056d23841502cdfe05d83f Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 20 Sep 2018 03:27:42 +0700 Subject: [PATCH] logged error handle for window module --- samples/sources/sample_00/sample_00.cpp | 3 +++ sources/enduro2d/core/window_impl/window.hpp | 1 + sources/enduro2d/core/window_impl/window_glfw.cpp | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/samples/sources/sample_00/sample_00.cpp b/samples/sources/sample_00/sample_00.cpp index 37cec703..0ff8b2e4 100644 --- a/samples/sources/sample_00/sample_00.cpp +++ b/samples/sources/sample_00/sample_00.cpp @@ -8,6 +8,9 @@ using namespace e2d; int main() { + modules::initialize(); + the().add_sink(); + window w{{640, 480}, "Enduro2D", false}; while ( !w.should_close() ) { w.swap_buffers(); diff --git a/sources/enduro2d/core/window_impl/window.hpp b/sources/enduro2d/core/window_impl/window.hpp index fb3abb34..77ea4892 100644 --- a/sources/enduro2d/core/window_impl/window.hpp +++ b/sources/enduro2d/core/window_impl/window.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include #define E2D_WINDOW_MODE_NONE 1 diff --git a/sources/enduro2d/core/window_impl/window_glfw.cpp b/sources/enduro2d/core/window_impl/window_glfw.cpp index bd130685..d24b4648 100644 --- a/sources/enduro2d/core/window_impl/window_glfw.cpp +++ b/sources/enduro2d/core/window_impl/window_glfw.cpp @@ -20,6 +20,7 @@ namespace class glfw_state : private noncopyable { public: glfw_state() { + glfwSetErrorCallback(error_handler); if ( !glfwInit() ) { throw bad_window_operation(); } @@ -27,6 +28,7 @@ namespace ~glfw_state() noexcept { glfwTerminate(); + glfwSetErrorCallback(nullptr); } public: static bool poll_events() noexcept { @@ -48,6 +50,16 @@ namespace private: static std::mutex mutex_; static std::shared_ptr shared_state_; + private: + static void error_handler(int error, const char* message) noexcept { + try { + the().error( + "GLFW: error(%0) message(%1)", + error, message); + } catch (...) { + // nothing + } + } }; std::mutex glfw_state::mutex_;