chore(ui): don't crash on unexpected scheduler pqueue len
This commit is contained in:
parent
493d7aeede
commit
05b7a9014d
|
@ -71,11 +71,11 @@ pub const State = struct {
|
|||
}
|
||||
};
|
||||
|
||||
pub fn draw(sync: *Synchro, state: *State, win_dim: Dimensions, tex_id: GLuint, cpu: *const Arm7tdmi) bool {
|
||||
pub fn draw(state: *State, sync: *Synchro, dim: Dimensions, cpu: *const Arm7tdmi, tex_id: GLuint) bool {
|
||||
const scn_scale = config.config().host.win_scale;
|
||||
const bus_ptr: *Bus = @ptrCast(@alignCast(cpu.bus.ptr));
|
||||
|
||||
zgui.backend.newFrame(@floatFromInt(win_dim.width), @floatFromInt(win_dim.height));
|
||||
zgui.backend.newFrame(@floatFromInt(dim.width), @floatFromInt(dim.height));
|
||||
|
||||
state.title = handleTitle(&bus_ptr.pak.title);
|
||||
|
||||
|
@ -90,15 +90,17 @@ pub fn draw(sync: *Synchro, state: *State, win_dim: Dimensions, tex_id: GLuint,
|
|||
state.should_quit = true;
|
||||
|
||||
if (zgui.menuItem("Insert ROM", .{})) blk: {
|
||||
const maybe_path = nfd.openFileDialog("gba", null) catch |e| {
|
||||
log.err("failed to open file dialog: {}", .{e});
|
||||
const file_path = tmp: {
|
||||
const path_opt = nfd.openFileDialog("gba", null) catch |e| {
|
||||
log.err("file dialog failed to open: {}", .{e});
|
||||
break :blk;
|
||||
};
|
||||
|
||||
const file_path = maybe_path orelse {
|
||||
break :tmp path_opt orelse {
|
||||
log.warn("did not receive a file path", .{});
|
||||
break :blk;
|
||||
};
|
||||
};
|
||||
defer nfd.freePath(file_path);
|
||||
|
||||
log.info("user chose: \"{s}\"", .{file_path});
|
||||
|
@ -118,15 +120,17 @@ pub fn draw(sync: *Synchro, state: *State, win_dim: Dimensions, tex_id: GLuint,
|
|||
}
|
||||
|
||||
if (zgui.menuItem("Load BIOS", .{})) blk: {
|
||||
const maybe_path = nfd.openFileDialog("bin", null) catch |e| {
|
||||
log.err("failed to open file dialog: {}", .{e});
|
||||
const file_path = tmp: {
|
||||
const path_opt = nfd.openFileDialog("bin", null) catch |e| {
|
||||
log.err("file dialog failed to open: {}", .{e});
|
||||
break :blk;
|
||||
};
|
||||
|
||||
const file_path = maybe_path orelse {
|
||||
break :tmp path_opt orelse {
|
||||
log.warn("did not receive a file path", .{});
|
||||
break :blk;
|
||||
};
|
||||
};
|
||||
defer nfd.freePath(file_path);
|
||||
|
||||
log.info("user chose: \"{s}\"", .{file_path});
|
||||
|
@ -340,9 +344,9 @@ pub fn draw(sync: *Synchro, state: *State, win_dim: Dimensions, tex_id: GLuint,
|
|||
const Event = std.meta.Child(@TypeOf(sched_ptr.queue.items));
|
||||
|
||||
var items: [20]Event = undefined;
|
||||
const len = sched_ptr.queue.len;
|
||||
const len = @min(sched_ptr.queue.len, items.len);
|
||||
|
||||
@memcpy(&items, sched_ptr.queue.items);
|
||||
@memcpy(items[0..len], sched_ptr.queue.items[0..len]);
|
||||
std.mem.sort(Event, items[0..len], {}, widgets.eventDesc(Event));
|
||||
|
||||
for (items[0..len]) |event| {
|
||||
|
@ -361,9 +365,9 @@ pub fn draw(sync: *Synchro, state: *State, win_dim: Dimensions, tex_id: GLuint,
|
|||
widgets.paletteGrid(.Object, cpu);
|
||||
}
|
||||
|
||||
{
|
||||
zgui.showDemoWindow(null);
|
||||
}
|
||||
// {
|
||||
// zgui.showDemoWindow(null);
|
||||
// }
|
||||
|
||||
return true; // request redraw
|
||||
}
|
||||
|
|
|
@ -225,9 +225,9 @@ pub const Gui = struct {
|
|||
SDL.SDL_LockAudioDevice(self.audio.device);
|
||||
defer SDL.SDL_UnlockAudioDevice(self.audio.device);
|
||||
|
||||
zgui_redraw = imgui.draw(sync, &self.state, win_dim, out_tex, cpu);
|
||||
zgui_redraw = imgui.draw(&self.state, sync, win_dim, cpu, out_tex);
|
||||
},
|
||||
.Inactive => zgui_redraw = imgui.draw(sync, &self.state, win_dim, out_tex, cpu),
|
||||
.Inactive => zgui_redraw = imgui.draw(&self.state, sync, win_dim, cpu, out_tex),
|
||||
}
|
||||
|
||||
if (zgui_redraw) {
|
||||
|
|
Loading…
Reference in New Issue