Advertisement

About using old objects after recompiling scripts

Started by July 21, 2015 02:44 PM
1 comment, last by Tzarls 9 years, 4 months ago

Hi Andreas. I have a small question regarding the usage of script objects...let me explain my situation so you can better understand what´s going on here:

I have 3 threads. One thread (let´s call it "main") can recompile the script upon user request. The other 2 threads (let´s call them "workers") create script objects and call their methods regularly. Both workers work at their own rate and can call objects´ methods a couple of times per second or several thousand times per second. Workers will be notified when the script has been recompiled by the main thread, and they will destroy the old objects (by calling their Release() method) and create new objects based on the new version of the script. The problem is that a recompilation can occur at any time and the workers may continue to use the old objects for some time before they have the opportunity to update them.

Now, as far as I´ve been able to test, having objects created with an old version of the script (even if the script has been recompiled) causes no problem at all. I´ve even had objects created with 3 different versions of the script, all living together, even if the older objects call global functions that no longer exist in the current compiled version of the script.

Is it ok to do it this way? Does Angelscript include some magic to make all of this work, or I have just been lucky, using some kind of ghost code that might eventually get cleaned up and cause my code to finally crash?

ps: I don´t care much about serializing my objects right now.

AngelScript uses magic to make it work. :)

Discarding a module doesn't immediately remove the module if there are still live objects or other external references to the module. It will be kept in memory until all those references are released in order to avoid dangling pointers, or other lose ends that may cause crashes in the application.

However, this also means that the re-compiled script doesn't share anything with the previous script (unless the script entities have been explicitly declared as shared). Global variables, object types, etc will be distinct for each compilation.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Great. Thanks! A little magic is always welcome!

This topic is closed to new replies.

Advertisement