GithubHelp home page GithubHelp logo

Comments (7)

quarnster avatar quarnster commented on July 22, 2024

Panicing variant when trying to use the return value of d.a as a function parameter:

package qml_test

import (
    "gopkg.in/qml.v1"
    "testing"
    "time"
)

func init() {
    qml.SetupTesting()
}

type (
    Blah struct {
        A int
    }
    dummy2 struct {
        b Blah
    }

    dummy struct {
        d dummy2
    }
)

func (d *dummy2) B() Blah {
    return d.b
}

func (d *dummy) C(*dummy2) {
}
func (d *dummy) A() *dummy2 {
    return &d.d
}

func TestBlah(t *testing.T) {
    //  qml.Init(nil)

    f := func() error {
        e := qml.NewEngine()
        defer e.Destroy()
        var d dummy
        e.Context().SetVar("d", &d)
        c, err := e.LoadString("blah.qml", `
import QtQuick 2.0
Item {
    Timer {
        objectName: "ti";
        interval: 10
        running: true
        repeat: true
        onTriggered: {
            running = false;
            console.log(d);
            var a = d.a();
            console.log(a);
            d.c(a);
            var b = a.b(0);
            console.log(b.a);
            running = true;
        }
    }
}
`)
        if err != nil {
            return err
        }
        w := c.Create(nil)
        defer w.Destroy()
        o := w.ObjectByName("ti") //.ObjectByName("ti")
        defer o.Destroy()
        failed := false
        for i := 0; i < 30; i++ {
            if b, ok := o.Property("running").(bool); !b && ok {
                failed = true
                break
            }
            time.Sleep(time.Second)
        }
        if failed {
            t.FailNow()
        }
        return nil
    }
    err := f()
    if err != nil {
        t.Error(err)
    }
}

Output:

2014/05/26 12:59:08 blah.qml:11: dummy(0x6e0ed60)
2014/05/26 12:59:08 blah.qml:13: dummy2(0x6837820)
2014/05/26 12:59:08 blah.qml:16: 0
2014/05/26 12:59:08 blah.qml:11: dummy(0x6e0ed60)
2014/05/26 12:59:08 blah.qml:13: dummy2(0x6837820)
2014/05/26 12:59:08 blah.qml:16: 0
2014/05/26 12:59:08 blah.qml:11: dummy(0x6e0ed60)
2014/05/26 12:59:08 blah.qml:13: dummy2(0x6837820)
2014/05/26 12:59:08 blah.qml:16: 0
2014/05/26 12:59:08 blah.qml:11: dummy(0x6e0ed60)
2014/05/26 12:59:08 blah.qml:13: null
panic: reflect: call of reflect.Value.Type on zero Value

goroutine 16 [running]:
runtime.panic(0x41a97c0, 0xc2080a4bc0)
    /Users/quarnster/code/3rdparty/go/src/pkg/runtime/panic.c:279 +0xf5
reflect.Value.Type(0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/quarnster/code/3rdparty/go/src/pkg/reflect/value.go:1836 +0x92
gopkg.in/qml%2ev1.hookGoValueCallMethod(0x6d21e50, 0xc208030360, 0x7fff00000001, 0x7fff5fbfc650)
    /Users/quarnster/code/go/src/gopkg.in/qml.v1/bridge.go:506 +0x31b
gopkg.in/qml%2ev1._Cfunc_applicationExec(0x41b6b60)
    gopkg.in/qml.v1/_obj/_cgo_defun.c:71 +0x31
gopkg.in/qml%2ev1.Run(0x0, 0x422fa78, 0x0, 0x0)
    /Users/quarnster/code/go/src/gopkg.in/qml.v1/bridge.go:68 +0x1b1
gopkg.in/qml%2ev1.qmain()
    /Users/quarnster/code/go/src/gopkg.in/qml.v1/testing.go:17 +0x30

goroutine 19 [finalizer wait]:
runtime.park(0x4064ab0, 0x42d6bf8, 0x42caec9)
    /Users/quarnster/code/3rdparty/go/src/pkg/runtime/proc.c:1354 +0x89
runtime.parkunlock(0x42d6bf8, 0x42caec9)
    /Users/quarnster/code/3rdparty/go/src/pkg/runtime/proc.c:1370 +0x3b
runfinq()
    /Users/quarnster/code/3rdparty/go/src/pkg/runtime/mgc0.c:2624 +0xcf
runtime.goexit()
    /Users/quarnster/code/3rdparty/go/src/pkg/runtime/proc.c:1430

goroutine 17 [syscall]:
runtime.goexit()
    /Users/quarnster/code/3rdparty/go/src/pkg/runtime/proc.c:1430

goroutine 20 [chan receive]:
testing.RunTests(0x422fb10, 0x42c3300, 0x1, 0x1, 0x1)
    /Users/quarnster/code/3rdparty/go/src/pkg/testing/testing.go:504 +0x917
testing.Main(0x422fb10, 0x42c3300, 0x1, 0x1, 0x42de540, 0x0, 0x0, 0x42de540, 0x0, 0x0)
    /Users/quarnster/code/3rdparty/go/src/pkg/testing/testing.go:435 +0x87
main.main()
    _/private/tmp/_test/_testmain.go:47 +0x9c
gopkg.in/qml%2ev1.tmain()
    /Users/quarnster/code/go/src/gopkg.in/qml.v1/testing.go:20 +0x1a
gopkg.in/qml%2ev1.func·035(0x0, 0x0)
    /Users/quarnster/code/go/src/gopkg.in/qml.v1/testing.go:17 +0x2c
gopkg.in/qml%2ev1.func·002()
    /Users/quarnster/code/go/src/gopkg.in/qml.v1/bridge.go:65 +0x46
created by gopkg.in/qml%2ev1.Run
    /Users/quarnster/code/go/src/gopkg.in/qml.v1/bridge.go:67 +0x1aa

goroutine 21 [sleep]:
time.Sleep(0x3b9aca00)
    /Users/quarnster/code/3rdparty/go/src/pkg/runtime/time.goc:39 +0x31
_/private/tmp_test.func·001(0x0, 0x0)
    /private/tmp/blah_test.go:78 +0x2d8
_/private/tmp_test.TestBlah(0xc208068090)
    /private/tmp/blah_test.go:85 +0x4f
testing.tRunner(0xc208068090, 0x42c3300)
    /Users/quarnster/code/3rdparty/go/src/pkg/testing/testing.go:422 +0x8b
created by testing.RunTests
    /Users/quarnster/code/3rdparty/go/src/pkg/testing/testing.go:503 +0x8cf
exit status 2
FAIL    _/private/tmp   2.077s

from qml.

niemeyer avatar niemeyer commented on July 22, 2024

The problem is the same described in this thread:

https://groups.google.com/d/msg/go-qml/h5gDOjyE8Yc/jyG9Pia2GaMJ

As explained there, the QML engine is destroying the old proxy object even though it was just handed a reference to it, which seems like bug, but I won't argue about that nor expect it to be timely fixed. Instead, I'm planning to simplify significantly the reference handling logic by making Go own all the values, and use its garbage collector to release resources on the QML side.

I'll keep you posted via this ticket.

from qml.

quarnster avatar quarnster commented on July 22, 2024

Got it, thanks, I'll keep my eyes and ears open :)

from qml.

niemeyer avatar niemeyer commented on July 22, 2024

Sorry it's taking a while to get to this. I'll move it up in the agenda and will go back to it after the new gl package structure is working.

from qml.

niemeyer avatar niemeyer commented on July 22, 2024

I'm back into this. Should have a fix shortly.

from qml.

niemeyer avatar niemeyer commented on July 22, 2024

Okay, rather than changing too much right now, I'm going for a more conservative approach which I should have implemented long ago.

from qml.

quarnster avatar quarnster commented on July 22, 2024

Excellent! Appears to work fine from very minor testing, thanks! :)

from qml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.