go-qml / qml

QML support for the Go language
Other
1.96k stars 187 forks source link

panic running customtype.go on windows #19

Closed tcoopman closed 9 years ago

tcoopman commented 10 years ago

When running customtype.go on windows I get following output:

I just tried running customtype.go on windows and I get an panic...

Text changed...
panic: invalid memory address or nil pointer dereference
fatal error: panic during malloc
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x41b2aa]

runtime stack:
runtime.panic(0x4cf6c0, 0x60c338)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/panic.c:233 +0x2b
runtime: unexpected return pc for runtime.sigpanic called from 0x6fcaef11

goroutine 4 [syscall]:
runtime.cgocall(0x487e4b, 0x3056d4)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/cgocall.c:149 +0x10c fp=0x3056c8
github.com/niemeyer/qml._Cfunc_objectGoAddr(0x25a7660, 0x13120358, 0x4b4240)
        C:/Users/THOMAS~1.PC1/AppData/Local/Temp/go-build936011503/github.com/niemeyer/qml/_obj/_cgo_defun.c:376 +0x33 fp=0x3056d4
github.com/niemeyer/qml.func┬╖016()
        c:/GoExt/src/github.com/niemeyer/qml/qml.go:384 +0x58 fp=0x3056f4github.com/niemeyer/qml.hookIdleTimer()
        c:/GoExt/src/github.com/niemeyer/qml/bridge.go:163 +0x53 fp=0x30570c
----- stack segment boundary -----
runtime.cgocallbackg1()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/cgocall.c:296 +0xb4 fp=0x305770
runtime.cgocallbackg()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/cgocall.c:266 +0x7a fp=0x305778
runtime.cgocallback_gofunc(0x403cb0, 0x48796b, 0x3057c4)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/asm_386.s:676 +0x57 fp=0x305788
runtime.asmcgocall(0x48796b, 0x3057c4)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/asm_386.s:584 +0x22 fp=0x30578c
runtime.cgocall(0x48796b, 0x3057c4)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/cgocall.c:149 +0x120 fp=0x3057b8
github.com/niemeyer/qml._Cfunc_applicationExec(0x6139a0)
        C:/Users/THOMAS~1.PC1/AppData/Local/Temp/go-build936011503/github.com/niemeyer/qml/_obj/_cgo_defun.c:61 +0x33 fp=0x3057c4
github.com/niemeyer/qml.guiLoop()
        c:/GoExt/src/github.com/niemeyer/qml/bridge.go:34 +0x54 fp=0x3057ccruntime.goexit()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/proc.c:1394 fp=0x3057d0
created by github.com/niemeyer/qml.Init
        c:/GoExt/src/github.com/niemeyer/qml/qml.go:58 +0x8c

goroutine 1 [chan receive]:
github.com/niemeyer/qml.gui(0x13129260)
        c:/GoExt/src/github.com/niemeyer/qml/bridge.go:62 +0x94
github.com/niemeyer/qml.(*Common).Interface(0x13120300, 0x0, 0x26c8c8)
        c:/GoExt/src/github.com/niemeyer/qml/qml.go:387 +0x93
main.run(0x0, 0x1)
        c:/Workspace/goqml/qml/examples/customtype/customtype.go:47 +0x120
main.main()
        c:/Workspace/goqml/qml/examples/customtype/customtype.go:10 +0x20

goroutine 3 [syscall]:
runtime.goexit()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist738819395/go/src/pkg/runtime/proc.c:1394
exit status 2
tcoopman commented 10 years ago

I've looked into this issue some more and found that the exact location of the cast is in capi.cpp at objectGoAddr running:

GoValue *goValue = dynamic_cast<GoValue *>(qobject);

As I was running go1.2rc4 before, I've tried running this with go1.2rc1 and I've got a different error: (it looks like this was changed by this issue: https://code.google.com/p/go/issues/detail?id=6419)

Text changed...
2013/11/14 10:04:18 capi.cpp:489: 0x3aa2dd8 //output of qDebug() << object
2013/11/14 10:04:18 capi.cpp:491: GoType(0x3aa2dd8) //output of qDebug() << qobject
fatal error: malloc/free - deadlock
[signal 0xc0000005 code=0x0 addr=0x10 pc=0x41b30a]

runtime stack:
runtime: unexpected return pc for runtime.sigpanic called from 0x6fcaef11
runtime.throw(0x6101e0)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/panic.c:464 +0x67
runtime.mallocgc(0x8, 0x0, 0x0)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/malloc.goc:51 +0x4f
runtime.mal(0x8)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/malloc.goc:700 +0x3a
copyin(0x4cfba0, 0x18d808, 0x18d814)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/iface.c:153 +0x5c
runtime.convT2E(0x4cfba0, 0x60f36f, 0x31, 0x4cfba0, 0x31)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/iface.c:221 +0x32
runtime.newErrorString(0x60f36f, 0x31, 0x18d830)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/error.go:74 +0x3a
runtime.panicstring(0x60f36f)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/panic.c:477 +0x82
runtime.sigpanic()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/os_windows.c:337 +0xb4
runtime.mallocgc(0x8, 0x0, 0x0)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/malloc.goc:70 +0xca
runtime.mal(0x8)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/malloc.goc:700 +0x3a
copyin(0x4cfba0, 0x18d8d0, 0x18d8dc)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/iface.c:153 +0x5c
runtime.convT2E(0x4cfba0, 0x60f358, 0x16, 0x4cfba0, 0x16)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/iface.c:221 +0x32
runtime.newErrorString(0x60f358, 0x16, 0x18d8f8)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/error.go:74 +0x3a
runtime.panicstring(0x60f358)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/panic.c:477 +0x82
runtime: unexpected return pc for runtime.sigpanic called from 0x6fcaef11
runtime.sigpanic()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/os_windows.c:336 +0xa7

goroutine 4 [syscall]:
runtime.cgocallbackg()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/cgocall.c:267 +0x7f fp=0x344e2c
runtime.cgocallback_gofunc(0x403af0, 0x4882eb, 0x344e78)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/asm_386.s:676 +0x57 fp=0x344e3c
runtime.asmcgocall(0x4882eb, 0x344e78)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/asm_386.s:584 +0x22 fp=0x344e40
runtime.cgocall(0x4882eb, 0x344e78)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/cgocall.c:149 +0x120 fp=0x344e6c
github.com/niemeyer/qml._Cfunc_objectGoAddr(0x3aa2dd8, 0x14450358, 0x1)
        C:/Users/THOMAS~1.PC1/AppData/Local/Temp/go-build007705559/github.com/niemeyer/qml/_obj/_cgo_defun.c:376 +0x33 fp=0x344e78
github.com/niemeyer/qml.func┬╖016()
        c:/Workspace/goqml/src/github.com/niemeyer/qml/qml.go:387 +0x19d fp=0x344ef4
github.com/niemeyer/qml.hookIdleTimer()
        c:/Workspace/goqml/src/github.com/niemeyer/qml/bridge.go:163 +0x53 fp=0x344f0c
----- stack segment boundary -----
runtime.cgocallbackg1()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/cgocall.c:296 +0xb4 fp=0x344f70
runtime.cgocallbackg()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/cgocall.c:266 +0x7a fp=0x344f78
runtime.cgocallback_gofunc(0x403af0, 0x487e0b, 0x344fc4)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/asm_386.s:676 +0x57 fp=0x344f88
runtime.asmcgocall(0x487e0b, 0x344fc4)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/asm_386.s:584 +0x22 fp=0x344f8c
runtime.cgocall(0x487e0b, 0x344fc4)
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/cgocall.c:149 +0x120 fp=0x344fb8
github.com/niemeyer/qml._Cfunc_applicationExec(0x616960)
        C:/Users/THOMAS~1.PC1/AppData/Local/Temp/go-build007705559/github.com/niemeyer/qml/_obj/_cgo_defun.c:61 +0x33 fp=0x344fc4
github.com/niemeyer/qml.guiLoop()
        c:/Workspace/goqml/src/github.com/niemeyer/qml/bridge.go:33 +0x54 fp=0x344fcc
runtime.goexit()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runtime/proc.c:1389 fp=0x344fd0
created by github.com/niemeyer/qml.Init
        c:/Workspace/goqml/src/github.com/niemeyer/qml/qml.go:58 +0x8c

goroutine 1 [chan receive]:
github.com/niemeyer/qml.gui(0x14452270)
        c:/Workspace/goqml/src/github.com/niemeyer/qml/bridge.go:62 +0x94
github.com/niemeyer/qml.(*Common).Interface(0x14450300, 0x0, 0x26c188)
        c:/Workspace/goqml/src/github.com/niemeyer/qml/qml.go:395 +0x93
main.run(0x0, 0x1)
        c:/Workspace/goqml/src/github.com/niemeyer/qml/examples/customtype/customtype.go:47 +0x120
main.main()
        c:/Workspace/goqml/src/github.com/niemeyer/qml/examples/customtype/customtype.go:10 +0x20

goroutine 3 [syscall]:
runtime.goexit()
        C:/Users/ADMINI~1/AppData/Local/Temp/2/bindist351444495/go/src/pkg/runti
me/proc.c:1389
exit status 2
niemeyer commented 10 years ago

Can you still reproduce this issue after the recent changes?

niemeyer commented 10 years ago

I'm closing this for the time being. Please reopen if you can reproduce the issue with Go 1.2 final.

niemeyer commented 10 years ago

Reopening as there was another report for this same bug:

https://groups.google.com/d/msg/go-qml/j-5Zdb7Lo7g/Q9RNRI2Atm0J

niemeyer commented 10 years ago

The fix on adf30a8 was confirmed to solve the problem.

xlab commented 10 years ago

Reproduced... https://groups.google.com/d/msg/go-qml/jwgVTL3TFzU/jEeTndgCV2wJ

niemeyer commented 10 years ago

Thanks, I'll review the bug and see if there's something I can identify in that code path.

xlab commented 10 years ago

https://github.com/xlab/goqml-customtype-fail here is a minimal PoC. Works as expected under go1.2.1 OSX, but fails under Windows mingw 4.8.1 go 1.2.1. After a bit of experimenting, it can be clearly seen that these methods failing in cgo backend: objectGetProperty, objectFindChild, and in case like original Interface() call - objectGoAddr. Hope this helps.

niemeyer commented 10 years ago

Can you please provide the failure traceback for that specific example?

Thanks!

On Wed, Apr 30, 2014 at 4:28 PM, Maxim Kouprianov notifications@github.comwrote:

https://github.com/xlab/goqml-customtype-fail here is a minimal PoC. Works as expected under go1.2.1 OSX, but fails under Windows mingw 4.8.1 go 1.2.1. After a bit of experimenting, it can be clearly seen that these methods failing in cgo backend: objectGetProperty, objectFindChild, and in case like original Interface() call - objectGoAddr. Hope this helps.

— Reply to this email directly or view it on GitHubhttps://github.com/go-qml/qml/issues/19#issuecomment-41863928 .

gustavo @ http://niemeyer.net

xlab commented 10 years ago

.Property("ctrl") - https://gist.github.com/xlab/e09445cee8a25d07dd2a .ObjectByName("ctrl") - https://gist.github.com/xlab/e3982b2f44319a44ebb9

niemeyer commented 10 years ago

Thanks for all the information.

Given that all these methods are failing, the problem is clearly at value creation time. So far I could not guess what might be wrong. Might need an environment to reproduce it.

niemeyer commented 9 years ago

The tracebacks seem to point towards bug #84, which is caused by an upstream bug:

A workaround was committed yesterday with b89e5bc8. I'm considering this fixed. Please reopen if any other evidence shows up.

neclepsio commented 9 years ago

(Moved here from #142, as it seems to be the correct place)

I have the same problem in ObjectByName. I tried to dumbly convert reinterpret_cast to static_cast (as per one of your fixes) but I get exactly the same error at runtime. ObjectByName works for non custom defined objects. I cannot run customtype.go example too, with the same stack trace.

In my tests i found out that objectGoAddr and objectFindChild fail, while objectGetProperty works.

I think issue this should be reopened.

With my program I get:

Exception 0xc0000005 0x8 0x0 0x0
PC=0x0
signal arrived during cgo execution

gopkg.in/qml%2ev1._Cfunc_objectFindChild(0x6d0f340, 0x6d306c0, 0xc08218a080)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/:287 +0x4c
gopkg.in/qml%2ev1.func·023()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/qml.go:671 +0xaf
gopkg.in/qml%2ev1.hookIdleTimer()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:190 +0x67
gopkg.in/qml%2ev1._Cfunc_applicationExec()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/:59 +0x4c
gopkg.in/qml%2ev1.Run(0x6d94c0, 0x0, 0x0)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:63 +0x20b
main.main()
    F:/Home-Mirror/Programming/Go-Workspace/src/df/gopher.go:33 +0x4b

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    c:/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 5 [running]:
    goroutine running on other thread; stack unavailable
created by main.initModels
    F:/Home-Mirror/Programming/Go-Workspace/src/df/gopher.go:97 +0xb4

goroutine 18 [chan receive]:
gopkg.in/qml%2ev1.RunMain(0xc0824e0060)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:88 +0xdd
gopkg.in/qml%2ev1.(*Common).ObjectByName(0xc0821a8000, 0x687730, 0x8, 0x0, 0x0)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/qml.go:684 +0x230
main.run(0x0, 0x0)
    F:/Home-Mirror/Programming/Go-Workspace/src/df/gopher.go:61 +0x232
gopkg.in/qml%2ev1.func·002()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:60 +0x50
created by gopkg.in/qml%2ev1.Run
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:62 +0x204
rax     0x814e60
rbx     0x6cb78d0
rcx     0x6db6a0
rdx     0x0
rdi     0x0
rsi     0x6db140
rbp     0x6d9d00
rsp     0x22bb58
r8      0x6
r9      0x6db140
r10     0x841250
r11     0x246
r12     0x22bd10
r13     0x22c360
r14     0xb79330
r15     0xb7ebe0
rip     0x0
rflags  0x10202
cs      0x33
fs      0x53
gs      0x2b

With customtype.go:

Text changing to: Happy birthday, Go!
Exception 0xc0000005 0x8 0x0 0x0
PC=0x0
signal arrived during cgo execution

gopkg.in/qml%2ev1._Cfunc_objectGoAddr(0x56be8c0, 0xc082065d20, 0x0)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/:299 +0x4b
gopkg.in/qml%2ev1.func·020()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/qml.go:488 +0x59
gopkg.in/qml%2ev1.hookIdleTimer()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:190 +0x67
gopkg.in/qml%2ev1._Cfunc_applicationExec()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/:59 +0x4c
gopkg.in/qml%2ev1.Run(0x5ae7e8, 0x0, 0x0)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:63 +0x20b
main.main()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/examples/customtype/customtype.go:11 +0x39

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    c:/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 5 [runnable]:
gopkg.in/qml%2ev1.RunMain(0xc082004bc0)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:85 +0xb8
gopkg.in/qml%2ev1.(*Common).Interface(0xc08200a5b0, 0x0, 0x0)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/qml.go:491 +0x126
main.run(0x0, 0x0)
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/examples/customtype/customtype.go:46 +0x221
gopkg.in/qml%2ev1.func·002()
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:60 +0x50
created by gopkg.in/qml%2ev1.Run
    F:/Home-Mirror/Programming/Go-Workspace/src/gopkg.in/qml.v1/bridge.go:62 +0x204
rax     0x675d00
rbx     0x56be8c0
rcx     0x5b0200
rdx     0x0
rdi     0x0
rsi     0x5b0060
rbp     0x5aeed0
rsp     0x22bc58
r8      0x6
r9      0x5b0060
r10     0x0
r11     0x246
r12     0x8cea20
r13     0x22c360
r14     0x8dc9a0
r15     0x336170
rip     0x0
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b
neclepsio commented 9 years ago

I found out part of the problem. Dumbly changing dynamic_cast to static_cast in objectGoAddr makes customtype.go work. I have no idea of possible side-effects.

About the problem in ObjectByName, the crash happens in line packDataValue(&var, resultdv);. I'm trying to do some just-a-bit-less-dumb modify. The offending line is in packDataValue (but so why does stack trace points to ObjectByName?): GoValue *goValue = dynamic_cast<GoValue *>(qobject);. Changing to static_cast stops crashing, but I get:

panic: reflect: call of reflect.Value.Call on complex128 Value

Looking for why can dynamic_cast crash, I found out http://stackoverflow.com/a/280031/1924721, but that didn't help me.

In the meantime, I discovered a simple std::cout<<"test"; crashes under Windows, maybe the C++ runtime is not initialized? So that dynamic_cast cannot access RTTI? Could this be related to noliar@352842b?

I opened https://github.com/golang/go/issues/10023.

niemeyer commented 9 years ago

Thanks. From the looks of it, it seems that there are major bugs in the C++ support in that environment. I'm tentatively closing this bug on qml and will follow up on golang/go#10023. If there is a reason to think go-qml is at fault somehow, please feel free to reopen this.

neclepsio commented 9 years ago

Using Go 1.5 solves this. Please update documents to state Go 1.5 is required under Windows.