grow-graphics / gd

Go + Godot 4.2.2
https://learn.grow.graphics/
MIT License
154 stars 4 forks source link

Hot reloading error on windows #30

Open puzzir opened 1 week ago

puzzir commented 1 week ago

System information

Godot Engine v4.2.2.stable.official.15073afe3 Microsoft Windows NT 10.0.19045.0

Issue description

Godot editor crashes with error while recompiling library.

Steps to reproduce:

  1. Сompile the code and run Godot (with gd command).
package main

import (
    "grow.graphics/gd"
    "grow.graphics/gd/gdextension"
)

type NewLabel struct {
    gd.Class[NewLabel, gd.Label]
}

func main() {
    godot, ok := gdextension.Link()
    if !ok {
        return
    }
    gd.Register[NewLabel](godot)
}
  1. Add a new object "NewLabel" in the Godot editor via "Add Chid Node".

  2. With the editor running, recompile the library.

gd build

or

go build -o ./graphics/windows_amd64.dll -buildmode=c-shared

Then Godot editor crashes with error:

ERROR: Cannot get class ''.          
   at: (core/object/class_db.cpp:407)
panic: runtime.link/mmm error: use after free                                                                                

goroutine 17 [running, locked to thread]:                                                                                    
grow.graphics/gd/gdextension.linkCGO.func80({{0x7ff85b0b2cf8?, 0xc0006c2000?}, 0x7ff85c4cc240?}, {{}, {0x6?, 0xc000624a50?}})
        D:/Golang/GOPATH/pkg/mod/grow.graphics/gd@v0.0.0-20240615231848-e0bdc0378103/gdextension/gdextension_interface.go:1755 +0x70
grow.graphics/gd.Engine(...)
        D:/Golang/GOPATH/pkg/mod/grow.graphics/gd@v0.0.0-20240615231848-e0bdc0378103/classdb.go:3643
grow.graphics/gd.(*instanceImplementation).Notification(0xc0001fa270, 0x3ea, 0xf8?)
        D:/Golang/GOPATH/pkg/mod/grow.graphics/gd@v0.0.0-20240615231848-e0bdc0378103/register_class.go:446 +0x63
grow.graphics/gd/gdextension.notification_func(0x0?, 0x3ea, 0x0)
        D:/Golang/GOPATH/pkg/mod/grow.graphics/gd@v0.0.0-20240615231848-e0bdc0378103/gdextension/gdextension_interface.go:2464 +0xa3
exit status 2
Splizard commented 1 week ago

I'm not sure how solvable this is, Go doesn't strictly support dlclose when compiled to a shared library, so you get these weird inconsistent issues when you reload the extension. In my case, it works sometimes, other times, Godot will crash.

Ullanar commented 3 days ago

Same here! But editor just closes silently. Without any additional logs