mach: set error message to be shown on glfw error

This uses glfw.setErrorCallback to set a global callback in mach's App
which would work across all mach applications
This commit is contained in:
iddev5 2022-04-17 23:48:08 +05:30 committed by Stephen Gutekanst
parent 27146af8ce
commit a922b4b29b

View file

@ -52,6 +52,11 @@ pub const Options = struct {
power_preference: gpu.PowerPreference = .none, power_preference: gpu.PowerPreference = .none,
}; };
/// Default GLFW error handling callback
fn glfwErrorCallback(error_code: glfw.Error, description: [:0]const u8) void {
std.debug.print("glfw: {}: {s}\n", .{ error_code, description });
}
/// A Mach application. /// A Mach application.
/// ///
/// The Context type is your own data type which can later be accessed via app.context from within /// The Context type is your own data type which can later be accessed via app.context from within
@ -87,6 +92,7 @@ pub fn App(comptime Context: type, comptime config: AppConfig) type {
pub fn init(allocator: std.mem.Allocator, context: Context, options: Options) !Self { pub fn init(allocator: std.mem.Allocator, context: Context, options: Options) !Self {
const backend_type = try util.detectBackendType(allocator); const backend_type = try util.detectBackendType(allocator);
glfw.setErrorCallback(glfwErrorCallback);
try glfw.init(.{}); try glfw.init(.{});
// Create the test window and discover adapters using it (esp. for OpenGL) // Create the test window and discover adapters using it (esp. for OpenGL)