glfw: correctly check for Monitor.getAll errors
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
6cfac34405
commit
309b71d600
1 changed files with 5 additions and 0 deletions
|
|
@ -197,6 +197,7 @@ pub inline fn getUserPointer(self: Monitor, comptime T: type) Error!?*T {
|
||||||
pub inline fn getAll(allocator: *mem.Allocator) ![]Monitor {
|
pub inline fn getAll(allocator: *mem.Allocator) ![]Monitor {
|
||||||
var count: c_int = 0;
|
var count: c_int = 0;
|
||||||
const monitors = c.glfwGetMonitors(&count);
|
const monitors = c.glfwGetMonitors(&count);
|
||||||
|
try getError();
|
||||||
|
|
||||||
const slice = try allocator.alloc(Monitor, @intCast(usize, count));
|
const slice = try allocator.alloc(Monitor, @intCast(usize, count));
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
|
|
@ -226,6 +227,10 @@ pub inline fn getPrimary() !?Monitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "getAll" {
|
test "getAll" {
|
||||||
|
const glfw = @import("main.zig");
|
||||||
|
try glfw.init();
|
||||||
|
defer glfw.terminate();
|
||||||
|
|
||||||
const allocator = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
const monitors = try getAll(allocator);
|
const monitors = try getAll(allocator);
|
||||||
defer allocator.free(monitors);
|
defer allocator.free(monitors);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue