From 9f9f40abd9aabb37b5171b7ba6f55e16b60c49a7 Mon Sep 17 00:00:00 2001 From: peterino2 Date: Sat, 3 Jan 2026 16:35:31 -0800 Subject: [PATCH] updates to engine time and seemingly bugs are fixed --- depot/zuck/main.zig | 3 ++- engine/core/src/core.zig | 6 +++--- engine/core/src/engine.zig | 3 ++- engine/core/src/engineTime.zig | 8 ++++++-- engine/main2.zig | 4 ++-- projects/tools/toolbox.zig | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/depot/zuck/main.zig b/depot/zuck/main.zig index e1e47f4..339dc55 100644 --- a/depot/zuck/main.zig +++ b/depot/zuck/main.zig @@ -21,7 +21,8 @@ pub fn tick(self: *@This(), dt: f64) void { } pub fn deinit(self: *@This()) void { - self.allocator.destroy(self); + // Engine handles memory deallocation + _ = self; } pub fn main() anyerror!void { diff --git a/engine/core/src/core.zig b/engine/core/src/core.zig index c029778..22baa50 100644 --- a/engine/core/src/core.zig +++ b/engine/core/src/core.zig @@ -172,7 +172,7 @@ pub const packer = @import("packer"); pub const StackCompactor = stacks.StackCompactor; -var staticsInitialized = false; +pub var staticsInitialized = false; var gEngine: *Engine = undefined; pub const PackerFS = packer.PackerFS; var gPackerFS: *PackerFS = undefined; @@ -274,8 +274,6 @@ pub fn maybeInitPackerFs(allocator: std.mem.Allocator) !void { } pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.Allocator) !void { - staticsInitialized = true; - if (map.get("utility")) |x| { if (x.boolean == true) { engine_logs("utility mode - no gui"); @@ -299,6 +297,8 @@ pub fn start_module_(map: *SpecVariantMap, args: anytype, allocator: std.mem.All gEngine = try allocator.create(Engine); gEngine.* = try Engine.init(allocator); + staticsInitialized = true; + _ = try createObject(ModuleLoader, .{}); try console.start(); diff --git a/engine/core/src/engine.zig b/engine/core/src/engine.zig index f60091e..95e6253 100644 --- a/engine/core/src/engine.zig +++ b/engine/core/src/engine.zig @@ -181,7 +181,7 @@ pub const Engine = struct { if (comptime core.BuildOption("static_build")) { newObjectPtr = @ptrCast(@alignCast((try self.allocator.alignedAlloc(u8, .@"16", vtable.typeSize)))); } else { - newObjectPtr = @ptrCast(@alignCast(&(try self.allocator.create(DebugSlack)).slack)); + newObjectPtr = @ptrCast(@alignCast((try self.allocator.create(DebugSlack)))); } try vtable.init_func(newObjectPtr, self.allocator, true); @@ -373,6 +373,7 @@ pub const Engine = struct { } fn destroyObject(self: *@This(), item: EngineObjectRef) void { + core.engine_log("destroying object {s}", .{item.vtable.typeName}); if (item.vtable.deinit_func) |deinitFn| { deinitFn(item.ptr); } diff --git a/engine/core/src/engineTime.zig b/engine/core/src/engineTime.zig index 0238ecb..161aa4c 100644 --- a/engine/core/src/engineTime.zig +++ b/engine/core/src/engineTime.zig @@ -5,8 +5,12 @@ const pscopes = core.algorithm.pscopes; // returns time since engine started in nanoseconds pub fn getEngineTime() f64 { - const read = core.getEngine().rootTimer.read(); - return @as(f64, @floatFromInt(read)) / std.time.ns_per_s; + if (core.staticsInitialized) { + const read = core.getEngine().rootTimer.read(); + return @as(f64, @floatFromInt(read)) / std.time.ns_per_s; + } + + return 0; } // returns a pscopes.TimingScope for the current time. diff --git a/engine/main2.zig b/engine/main2.zig index aca091c..e20e2f9 100644 --- a/engine/main2.zig +++ b/engine/main2.zig @@ -108,8 +108,8 @@ pub fn startEngine(spec: *core.SpecVariantMap) bool { run() catch return false; - if (core.getEngine().shutdownModuleFunction) |f| { - f(); + if (core.getEngine().shutdownModuleFunction) |shutdownFunc| { + shutdownFunc(); } else { core.shutdown_module(allocator); } diff --git a/projects/tools/toolbox.zig b/projects/tools/toolbox.zig index dac56e9..14b5a08 100644 --- a/projects/tools/toolbox.zig +++ b/projects/tools/toolbox.zig @@ -258,7 +258,7 @@ fn displayInstructions(self: *@This()) void { pub fn deinit(self: *@This()) void { self.animationStore.destroy(); - self.allocator.destroy(self); + // Engine handles memory deallocation } fn copyRecursiveDir(