fix invalid free
This commit is contained in:
@@ -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(), .{});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user