I keep getting an error `runtime assert: Must be p...
# kotlin-native
s
I keep getting an error
runtime assert: Must be positive
in my project that uses GTK interop, and I have no idea what's causing it. It's raised by konan, in the
garbageCollect
function.
d
Are you doing any multithreading?
s
Only as much multithreading as GTK is using. This error happens when I click the reset button in my application a certain number of times. That number depends on how much memory the callback allocates, seemingly
d
In my experience, this happens when a reference counter drops below zero. Which as you can imagine is very bad.
Odds are you are doing something with
DetachedObjectGraph
/`StableRef` that is very naughty.
s
👀
Something like-- and this is a hypothetical, I absolutely haven't done this-- disposing a
StableRef
and then continuing to use it? Not that I've done it, I'm just curious.
d
🤯 Yes, that would be very naughty.
If it was actually being done. 🙂
Another would be, passing a
StableRef
across threads, without freezing the object first.
👆 1
s
Thanks for the help! I managed to fix it, although it had NOTHING to do with what I described, not at all. 😅
k
What was it?
☝🏼 1
s
I was being facetious. What I described is exactly what it was.
k
Ah. I just skimmed your message. Actually reading it I see what you did there
Accessing memory you’ve killed can be tough

https://www.youtube.com/watch?v=qtK0KMH-8xs

s
Specifically, it was defining a stable ref for a GTK callback, and then disposing of it at the end of the callback. Since the callback could be used multiple times, the ref would also be used and disposed of multiple times, eventually leading to a segfault.
k
Yeah. Good times.