Pointers not explicitly assigned in QML may change or even become null

101 views
Skip to first unread message

Maxim Kouprianov

unread,
Apr 16, 2014, 1:11:03 PM4/16/14
to go-...@googlegroups.com
Hello, group. I'm not sure if my issue is connected with that one "Value lost from Go to QML?", but I see that behavior in my code too.
For example, I have the following specification to be rendered in QML:
type PlaceSpec struct {
X, Y     float64
Control  *ControlPointSpec
}

And this object is referenced within another specification:
type ArcSpec struct {
Place      *PlaceSpec
Index      int

Since there is no way (as for now) to pass a slice of specs into QML, I have set up a simple JS-procedure to form a list, getting values from Go land using index:
var a = model.value(i)
arcs[i] = {
    "place": a.place,
    "index": a.index,
}
Exactly every 47-48 times reading arcs[i].place.control yields null and then pointer address changes.
I think that's because of Go's GC machinery, but the master Gustavo should know better indeed.

The fix I've used in my case is to explicitly assign that pointer to a var/field, as follows:
arcs[i] = {
    "place": a.place, "control": a.place.control,
    "index": a.index,
}
Since then I use that object as arcs[i].control, but arcs[i].place.control works perfectly well too, now.
I hope that info would help someone.
Cheers.


Gustavo Niemeyer

unread,
Apr 16, 2014, 1:35:43 PM4/16/14
to Maxim Kouprianov, Go QML
In theory, values provided from Go to QML are properly tracked so that
they won't be garbage collected while being used. The fact the pointer
changes is surely a good hint that there's something else going on in
the code, but I cannot tell what it is since there's no code available
in the report.

Can you provide a small self-contained reproducer we could look at?
> --
> You received this message because you are subscribed to the Google Groups
> "go-qml" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to go-qml+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

gustavo @ http://niemeyer.net

Maxim Kouprianov

unread,
Apr 16, 2014, 1:48:55 PM4/16/14
to go-...@googlegroups.com, Maxim Kouprianov
Surely I've tried to create a small self-contained reproducer, but seems that this thing happens frequently only in relatively complex cases. In my reproducer the chance to catch a null was not so determinant and very rare, even the general structure of object relations was copied 1:1 from my project.

I'll submit my code which will help debug that behavior, but only after April 21st. ;)

среда, 16 апреля 2014 г., 21:35:43 UTC+4 пользователь Gustavo Niemeyer написал:

Gustavo Niemeyer

unread,
Apr 16, 2014, 1:57:33 PM4/16/14
to Maxim Kouprianov, Go QML
Sounds good. :-) I'll be happy to help then.

Are you going to be in GopherCon? We can also spend some time
together on this if you're there.

Maxim Kouprianov

unread,
Apr 21, 2014, 5:16:37 PM4/21/14
to go-...@googlegroups.com, Maxim Kouprianov
I've found a way to do a minimal self-contained example. The problem was that I've tried to make heavy objects on the Go's side, but actually heavy work on the QML side only matters. Slightly-documented example is there: https://github.com/xlab/goqml-null ready for investigations.

> Are you going to be in GopherCon?
Nope, need to finish my degree this month.

среда, 16 апреля 2014 г., 21:57:33 UTC+4 пользователь Gustavo Niemeyer написал:

Gustavo Niemeyer

unread,
Apr 22, 2014, 4:15:15 PM4/22/14
to Maxim Kouprianov, Go QML
Thanks for the reproducer. With that and a couple of debug messages,
it's easy to see where the problem is coming from:

2014/04/22 17:00:13 view.qml:30: pointer: Bar(0x211afb0)
[DEBUG] Returning existing cvalue for &main.Bar{}: 211afb0
2014/04/22 17:00:13 view.qml:33: pointer: null delta: 22
[DEBUG] value destroyed: cvalue=211afb0 gvalue=8ae228/&main.Bar{}

The QML engine is destroying the old proxy object even though it was
just handed a reference to it. Will investigate the best way to fix
this.

By the way, have you seen my note about your application for the
contest? Can you please send again, as the original one did not
arrive?

Maxim Kouprianov

unread,
Apr 22, 2014, 4:41:31 PM4/22/14
to go-...@googlegroups.com
I'm glad that the source was found that fast. O_o

> By the way, have you seen my note about your application for the contest?
Yes, and I've sent new copies immediately. The first time I've used gustavo....@canonical.com, now sent to gus...@niemeyer.net and niem...@canonical.com.

My email in all these letters is ma...@kouprianov.com.
Things getting strange.

среда, 23 апреля 2014 г., 0:15:15 UTC+4 пользователь Gustavo Niemeyer написал:

Gustavo Niemeyer

unread,
Apr 22, 2014, 5:08:42 PM4/22/14
to Maxim Kouprianov, Go QML
I don't have a single message coming from this address.

Can you please put the file somewhere online and provide a link in this thread?

Gustavo Niemeyer

unread,
Apr 22, 2014, 5:10:41 PM4/22/14
to Maxim Kouprianov, Go QML
Nevermind. Got your third attempt when you used the Google address.

The messages are not in the spam folder either, FWIW. You might get a
notice back from the SMTP server at some point, telling you what went
wrong.
Reply all
Reply to author
Forward
0 new messages