I’m encountering this a lot when I try to delete an object from it’s behaviour. It happens regularly whether I do it in javascript or through the action event. I’m not quite sure what it means, am I going about deleting objects incorrectly?
Under further investigation, I think it’s related to using the linked objects manager. I’m unlinking two objects before deleting one and I believe that this error happens on the frame after unlinking.
If I delete the object without unlinking, it errors.
If I unlink without deleting, it errors.
If I neither unlink nor delete it’s fine (because nothing has happened)
Is there special behaviour around deleting an object that’s linked to another?
Just unlinking objects shouldn’t make this kind of error happen. If I remember correctly when linking it just sets a property of each object to the object id of the other one. How do you delete objects? When do you delete objects? Maybe it’s related to the fact that you use that in a behavior lifecycle function, meaning you modify the object list while it is being iterated over wich could cause bugs if proper checks aren’t present.
This sounds reasonable, is there a better place to delete objects? What kinds of checks should be done to delete outside of the behaviour lifecycle?
I’ve tried deleting objects both in code (marking them with the runtimeScene for deletion) and with the eventsheet ‘object → delete’
My question was how do you exactly delete them (could you show me actual code please?) and where (in a behavior lifecycle, in the regular event sheet etc). Could you answer those questions please? I want to be sure that I am not missunderstanding your problem
I appreciate your help, thank you. The image below is how I was doing it. It’s taking place in a behaviour lifecycle, doStepPostEvents.
Do you get the same error on unlinking only or another one? Your code seems correct at first glance and the runtime code seems to have protections against this kind of errors. Do the object has any other behavior? This issue is very weird.
I get the same error on unlinking only. I should clarify that the error seems to occur on the frame after unlinking.
That’s a good question, the object does have a Draggable behaviour. I’ve tried disabling the behaviour but it doesn’t seem to have much effect.
At first glance I would say the error comes from runtimeScene._constructListOfAllInstances()
. It is a very weirdly made function so there could be a bug. But I don’t see how unlinking objects in a lifecycle function would cause it to go crazy. Btw little tip use gdjs.LinksManager.getManager(runtimeScene)
instead of using directly the Instance on runtimeScene, even if you know it is initialized, it’s cleaner to do so.
Thanks for the code tip!
Thanks for helping dig into this. I’ll try searching around for unintended side-effects with other objects or behaviours trying to access the object once it’s been unlinked.
We need take a look on pile of execution.
If the object is deleted and stepBehaviorsPostEvents is call after, this can be a problem because stepBehaviorsPostEvents use the instance of the object.
Then if the object doesn’t existing anymore, the app crash.
Can you show the rest of your code? I thought a bit and if indeed it is on the next frame, that means the all instances list constructor method is called for the regular events before already and the pre events functions, so it may be related to some other code calling something weird?
To troubleshoot more, did you try on another object without any other behavior? Did you try your extension in another project? Did you try to delete objects in another extension in lifecycle functions?
I appreciate all the help and I would be interested into digging more into it when I’m free.
I managed to workaround my issue by not using the linked objects manager and being careful about whether i delete objects or instead just hide them from view.