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;
int main() {
modules::initialize<debug>();
the<debug>().add_sink<debug_console_sink>();
window w{{640, 480}, "Enduro2D", false};
while ( !w.should_close() ) {
w.swap_buffers();

View File

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

View File

@@ -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<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_;