fix invalid free

This commit is contained in:
Ádám Kovács
2025-05-29 11:04:43 +02:00
parent 53b93bad64
commit ba172cc8ed
3 changed files with 6 additions and 4 deletions

View File

@@ -413,7 +413,8 @@ pub fn main() !void {
var app = try vxfw.App.init(allocator);
defer app.deinit();
const asd = Observer(*Tab){
const childrenLoadedObserver = try allocator.create(Observer(*Tab));
childrenLoadedObserver.* = Observer(*Tab){
.ctx = @ptrCast(@alignCast(&app)),
.update = (struct{fn update(ctx: *anyopaque, _: *Tab)void {
const app1: *vxfw.App = @ptrCast(@alignCast(ctx));
@@ -421,7 +422,7 @@ pub fn main() !void {
}}).update,
};
try app_common_model.appState.tabChildrenLoaded.attach(&asd);
try app_common_model.appState.tabChildrenLoaded.attach(childrenLoadedObserver);
try app.run(model.widget(), .{});

View File

@@ -45,7 +45,8 @@ pub const AppState = struct {
} else null;
if (index) |i| {
tab.childrenLoaded.observers.swapRemove(i);
const removed = tab.childrenLoaded.observers.swapRemove(i);
self.allocator.destroy(removed);
}
//TODO: remove from tabs

View File

@@ -12,7 +12,7 @@ pub fn Observable(T: type) type {
}
pub fn deinit(self: *Self) void {
for(self.observers)|o| {
for(self.observers.items)|o| {
self.allocator.destroy(o);
}
self.observers.deinit();