LoadCodeFromStream and "Clear"...

Hello,



In one program users create projects that include scripts.

In another program the project and scripts are executed. In this program users can also debug and edit scripts.



When the second program starts, all the scripts are compiled and the code is saved in memory streams.

When required, the various saved script code is loaded from a stream and executed using LoadCodeFromStream.



Now I am adding DLL support.

I am using SelfRegisterAsLibrary, at program start, on a script to load the user DLL defines into the script engine.



The issue is LoadCodeFromStream calls ?Clear? and removes the library from the script engine.



How can I keep the script loaded with SelfRegisterAsLibrary from removal when LoadCodeFromStream is called? Or another solution that does not require tons of rework on the current LoadCodeFromStream logic. It has been working for a few years.



Using SelfRegisterAsLibrary before each script is called would be inefficient.



Ideas?



Thanks,



Mark



Hello Mark,

LoadCodeFromStream should call Clear only for the script being loaded. Do you have a sample project reproducing the problem? Also, it's recommended that you first load all saved scripts, then call SelfRegisterAsLibrary after you've done loading. There is also an option where you load all of your script libraries in one TatScripter component, and then register those scripts as libraries in other scripter components.


Yes, but, if you look at the code, that is not what it does.



I have not made one. I see the issue in the code. Clear is called and "Clear" removes all scripts marked as library.



I have only one script that is set to register as a library.

Where is that in code? Clear just unregisters the script itself if it's registered as library.



I stated it wrong. Here is the code.

      { Unregister this script whenever it is registered as a library }
      while FLibraries.Count > 0 do
        SelfUnregisterAsLibrary(TatScriptBasedLibrary(FLibraries[0]).Scripter);


That 0 unregisters the first script that is loaded, which is the library in my case.

That's not what that code means. FLibraries is a list of meta information for all the times that specific script was registered as a library (because you can register the same script as a library multiple times, in different scripts).

The [0] index just unregisters the first instance, it doesn't matter because all instances will be unregistered anyway (while FLibraries.Count > 0). But again, this relates only to that specific script being cleared.

Well, I guess I will need to make you another example. The library IS being removed when Load is called. I do not know the code is well as you do but I do see the result.



I could be wrong, but after an hour or so tracing it down, that was were the code stepping lead me.



Waiting on the memory leak example, response

I'm not saying it's not a problem in scripter, but it's hard to tell just from code. That code is supposed to work like that. If you could send us the code to reproduce the problem, we can fix it for you. The memory leak was solved.

OK



The source files you sent me that corrected the Tatdll memory leak have also handled this issue.



Thanks for you help.