v icon indicating copy to clipboard operation
v copied to clipboard

Referenced struct is an empty struct after running app.gg.run()

Open Linklancien opened this issue 1 year ago • 0 comments

Describe the bug

The value of the referenced struct is an empty struct after running app.gg.run()

Reproduction Steps

import gg

struct Mass_Points {
mut :
    x f64
    y f64
    z f64
    m f64
    r f64
}

@[heap]
struct Soft_Body {
mut :
    list_mp []&Mass_Points
}


struct App {
mut:
    gg    &gg.Context = unsafe { nil }
    mass_points   []Mass_Points
    body        Soft_Body
}

fn main() {
    mut app := &App{}
    app.gg = gg.new_context(
        user_data: app
        frame_fn: on_frame
    )

    // Init
    app.body = Soft_Body{[]}
    xmax := 5
    mut list := []int{len: xmax, init:0}
    for x in 0 .. xmax {
        app.mass_points << Mass_Points{1, 1, 1, 1, 1}
        app.body.list_mp << &app.mass_points[app.mass_points.len - 1]
        list[x] = app.mass_points.len - 1
    }

    // Print before problem
    for at in app.body.list_mp{
        print("$at.x ") // only print the X but the whole struct is empty
    }

    println("disappear:")
    app.gg.run()
}

fn on_frame(mut app App) {
    // print the problem (after the launch of the app)
    for at in app.body.list_mp {
        print("$at.x ")
    }
    exit(0)
}

Expected Behavior

1.0 1.0 1.0 1.0 1.0 disappear:
1.0 1.0 1.0 1.0 1.0 

Current Behavior

1.0 1.0 1.0 1.0 1.0 disappear:
1.0 1.0 0.0 0.0 1.0 

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 89f06d3

Environment details (OS name and version, etc.)

windows, Microsoft Windows 10 Famille v19045 64 bits

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

Linklancien avatar Jan 08 '24 20:01 Linklancien