#Struct resets to defaults after `return`

1 messages · Page 1 of 1 (latest)

tough arrow
#

My state module loses some values in between updates. Here's what I'm calling:

const Comp = struct {
    Comp_Attack: u8 = 0, // some props omitted
}; // other stuff omitted
const FxMap = struct {
    COMP: std.meta.Tuple(&.{ u8, ?Comp }),
};
const Track = struct {
    fxMap: FxMap = FxMap{},
};

const State = @This();
track: ?Track = null,
pub fn updateTrack(self: *State) void {
    self.track = Track.init();
    // parse some config files into track.FxMap
    self.track.?.parseConfig(); // inside, it sets track.fxMap.Comp.Comp_Attack = 1
    return; // once here, self.track.fxMap.Comp.Comp_Attack is back to 0
}

I can't figure out why the values are being dropped back to default upon return. Inside track.parseConfig(), I'm setting the value like this:

pub fn parseConfig( self: *Track) void {
    self.fxMap.COMP = .{ 3, Comp{ Comp_Attack: 1 } };
}

and I see the value being set correctly. It prints to console and to the debugger alright.
Once I get to the return statement of updateTrack(), the value pf self.track.?.fxMap.COMP[1].Comp_Attack is back to 0.

What am I missing?
Sorry this data structure is so convoluted.

heady zephyr
#

where is updateTrack() called from? That code looks perfectly fine