logged error handle for window module

This commit is contained in:
2018-09-20 03:27:42 +07:00
parent 3d8ad71a93
commit a8f73821ca
3 changed files with 16 additions and 0 deletions

View File

@@ -8,6 +8,9 @@
using namespace e2d; using namespace e2d;
int main() { int main() {
modules::initialize<debug>();
the<debug>().add_sink<debug_console_sink>();
window w{{640, 480}, "Enduro2D", false}; window w{{640, 480}, "Enduro2D", false};
while ( !w.should_close() ) { while ( !w.should_close() ) {
w.swap_buffers(); w.swap_buffers();

View File

@@ -6,6 +6,7 @@
#pragma once #pragma once
#include <enduro2d/core/debug.hpp>
#include <enduro2d/core/window.hpp> #include <enduro2d/core/window.hpp>
#define E2D_WINDOW_MODE_NONE 1 #define E2D_WINDOW_MODE_NONE 1

View File

@@ -20,6 +20,7 @@ namespace
class glfw_state : private noncopyable { class glfw_state : private noncopyable {
public: public:
glfw_state() { glfw_state() {
glfwSetErrorCallback(error_handler);
if ( !glfwInit() ) { if ( !glfwInit() ) {
throw bad_window_operation(); throw bad_window_operation();
} }
@@ -27,6 +28,7 @@ namespace
~glfw_state() noexcept { ~glfw_state() noexcept {
glfwTerminate(); glfwTerminate();
glfwSetErrorCallback(nullptr);
} }
public: public:
static bool poll_events() noexcept { static bool poll_events() noexcept {
@@ -48,6 +50,16 @@ namespace
private: private:
static std::mutex mutex_; static std::mutex mutex_;
static std::shared_ptr<glfw_state> shared_state_; static std::shared_ptr<glfw_state> shared_state_;
private:
static void error_handler(int error, const char* message) noexcept {
try {
the<debug>().error(
"GLFW: error(%0) message(%1)",
error, message);
} catch (...) {
// nothing
}
}
}; };
std::mutex glfw_state::mutex_; std::mutex glfw_state::mutex_;