mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
logged error handle for window module
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <enduro2d/core/debug.hpp>
|
||||
#include <enduro2d/core/window.hpp>
|
||||
|
||||
#define E2D_WINDOW_MODE_NONE 1
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user