Jump to content
  • Advertisement
Sign in to follow this  
Tzarls

About using old objects after recompiling scripts

This topic is 1240 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by Tzarls

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!