Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Struct procedure members wipe struct members when called

Open spindlebink opened this issue 3 years ago • 0 comments

When calling a procedure that's a member of a struct and passing the struct by value as an argument, the struct appears most of the time to be uninitialized within the procedure.

package main

import "core:fmt"

Proc_Struct :: struct {
    call_me: proc(s: Proc_Struct),
    num: int,
    raw: rawptr,
}

other_call :: proc(from: Proc_Struct) {
    fmt.println(from.raw)
    fmt.println(from.num)
}

main :: proc() {
	ptr_value := 10
	s1 := Proc_Struct{
		call_me = proc(from: Proc_Struct) {
		    fmt.println(from.raw)
		    fmt.println(from.num)
		},
		num = ptr_value,
		raw = &ptr_value,
	}

	fmt.println(rawptr(&ptr_value))
	fmt.println(ptr_value)
	s1.call_me(s1)
	other_call(s1)
}

On my machine, the above code shows me:

0x7FFED775FA30
10
0x432CA0
0
0x7FFED775FA30
10

Where the output says 0x432CA0 and 0, the above code should print the value of ptr_value (10) and the address of the value (0x7FFED775FA30 in the run whose output I've pasted above).

From what I can tell using git bisect, this bug shows up around commit 0c9aaed9f741c3b96c63e0cbc9e4e11f4510248a.

Odin report:

Odin: dev-2022-09:729ffeee
OS:   Manjaro Linux, Linux 5.15.60-1-MANJARO
CPU:  12th Gen Intel(R) Core(TM) i5-12600K
RAM:  15791 MiB

spindlebink avatar Sep 18 '22 01:09 spindlebink