Prevent memory errors on home page
This commit is contained in:
parent
aa9656a089
commit
61bcf53b33
3 changed files with 12 additions and 1 deletions
10
src/home.zig
10
src/home.zig
|
@ -72,6 +72,8 @@ fn fetchThread(state: *AppState) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
state.home_screen_state.mutex.lock();
|
||||||
|
defer state.home_screen_state.mutex.unlock();
|
||||||
if (state.home_screen_state.suggestions.len > 0) {
|
if (state.home_screen_state.suggestions.len > 0) {
|
||||||
for (state.home_screen_state.suggestions) |suggestion| {
|
for (state.home_screen_state.suggestions) |suggestion| {
|
||||||
allocator.free(suggestion.id);
|
allocator.free(suggestion.id);
|
||||||
|
@ -94,8 +96,14 @@ pub fn render(state: *AppState) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
while (raylib.GetCharPressed()) |char| {
|
while (raylib.GetCharPressed()) |char| {
|
||||||
hs.station_name.appendAssumeCapacity(@intCast(char));
|
if (hs.station_name.items.len < hs.station_name_max_len) {
|
||||||
|
hs.station_name.appendAssumeCapacity(@intCast(char));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.home_screen_state.mutex.lock();
|
||||||
|
defer state.home_screen_state.mutex.unlock();
|
||||||
|
|
||||||
while (raylib.GetKeyPressed()) |key| {
|
while (raylib.GetKeyPressed()) |key| {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
rl.KEY_BACKSPACE => {
|
rl.KEY_BACKSPACE => {
|
||||||
|
|
|
@ -32,6 +32,7 @@ pub fn main() !void {
|
||||||
.ns_font = raylib.LoadFontEx("./private/ns.ttf", 64, cp, cp_cnt),
|
.ns_font = raylib.LoadFontEx("./private/ns.ttf", 64, cp, cp_cnt),
|
||||||
.home_screen_state = .{
|
.home_screen_state = .{
|
||||||
.station_name = std.ArrayListUnmanaged(u8).initBuffer(&station_name_buffer),
|
.station_name = std.ArrayListUnmanaged(u8).initBuffer(&station_name_buffer),
|
||||||
|
.station_name_max_len = station_name_buffer.len - 1,
|
||||||
},
|
},
|
||||||
.departure_screen_state = .{
|
.departure_screen_state = .{
|
||||||
.platform = std.ArrayListUnmanaged(u8).initBuffer(&platform_buffer),
|
.platform = std.ArrayListUnmanaged(u8).initBuffer(&platform_buffer),
|
||||||
|
|
|
@ -13,7 +13,9 @@ pub const HSSuggestion = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const HomeScreenState = struct {
|
pub const HomeScreenState = struct {
|
||||||
|
mutex: std.Thread.Mutex = .{},
|
||||||
station_name: std.ArrayListUnmanaged(u8),
|
station_name: std.ArrayListUnmanaged(u8),
|
||||||
|
station_name_max_len: usize,
|
||||||
fetch_thread: ?std.Thread = null,
|
fetch_thread: ?std.Thread = null,
|
||||||
suggestions: []HSSuggestion = &.{},
|
suggestions: []HSSuggestion = &.{},
|
||||||
selection_idx: i8 = 0,
|
selection_idx: i8 = 0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue