Closed xudongzheng closed 5 months ago
The following code results in a fault:
package main import "time" var timer = time.NewTimer(time.Second * 5) func main() { println("Hello world!") }
Issue also happens if time.NewTimer() is called from init().
time.NewTimer()
init()
The following code works correctly
package main import "time" var timer *time.Timer func main() { timer = time.NewTimer(time.Second * 5) println("Hello world!") }
This was tested on both desktop tinygo build -o ~/hello ~/hello.go and RP2040 Pico.
tinygo build -o ~/hello ~/hello.go
It looks like tn.timer.f here is nil: https://github.com/tinygo-org/tinygo/blob/f4395147039fc356277399853821cb772ebda883/src/runtime/time.go#L39
tn.timer.f
nil
Thanks, here is a fix: https://github.com/tinygo-org/tinygo/pull/4134
Thanks! Closing as I've confirmed the fix.
The following code results in a fault:
Issue also happens if
time.NewTimer()
is called frominit()
.The following code works correctly
This was tested on both desktop
tinygo build -o ~/hello ~/hello.go
and RP2040 Pico.It looks like
tn.timer.f
here isnil
: https://github.com/tinygo-org/tinygo/blob/f4395147039fc356277399853821cb772ebda883/src/runtime/time.go#L39