Reading the code, it looks like the bug might be that Sprite.cpp's destructor just unref() its children, while it should also clear their parent link to NULL!
EDIT: Just did that and the example you gave above no longer crashes!
This change may be necessary. I have committed it in pull request #296
@hgy29 maybe you should also check again the change in the lua binder code. It's not easy to determine if unref is needed when call stop in lua if the unref is not done in the stop function. I see the reason you do not directly unref in stop maybe because of the loop in nextFrame. Maybe you can consider to put it into an autounref pool in stop to unref it in next run loop just like remove a child do.Then only the play and stop functions require modified,all the other modifications can just be reverted to the original.
Thanks, its true I forgot the unref() in lua binder. Let me fix this. I cannot use autounrefpool since its implementation seems to release objects immediately when destroying the pool, I mmuch more confident on propagating the unref() request back to the frame event as I did. But I'll remove this dependance from luabinding somehow.
Yes, a local pool can not retain the unref objects until next run loop. I thought there would be a thread-scope pool like autorelease pool exists, but no.
Well if I unref() too early, the MC will be freeed at once so the code will no longer be able to read properties or call other methods without crashing, so its best to propagate the information as much as possible so as to free just before the final 'return'.
BTW I appreciate a lot your contributions to the code, we are too few guys to maintain Gideros, thanks for that!
Comments
Edit:it maybe not required, MC will stop itself after collected.
maybe you should also check again the change in the lua binder code.
It's not easy to determine if unref is needed when call stop in lua if the unref is not done in the stop function.
I see the reason you do not directly unref in stop maybe because of the loop in nextFrame.
Maybe you can consider to put it into an autounref pool in stop to unref it in next run loop just like remove a child do.Then only the play and stop functions require modified,all the other modifications can just be reverted to the original.
I thought there would be a thread-scope pool like autorelease pool exists, but no.
BTW I appreciate a lot your contributions to the code, we are too few guys to maintain Gideros, thanks for that!
Likes: MoKaLux