🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

AS 2.0 Bug: Compiler crash when working with handle and don't have addref/release

Started by
5 comments, last by WitchLord 19 years, 5 months ago
When working with handles and you don't register the addref/release behaviours for that class the compiler crash in as_builder.cpp at line 1152. Here is an example: Add an application function to the engine with the following declaration: "iStorage@ NewSubStorage(bstr ∈ name, bstr ∈ device)" Don't declare addref/release for iStorage class. When using the NewSubStorage function in a script the compiler crash during compilation. I think that the compiler should detect that the handle reference count functions are not declared and exit with a compilation error. Also, I don't know if the addref/release behaviour are necessary for classes registered with size zero (script cannot create objects of that class). I'm having all sorts of compilation crashes when using handles to objects from classes without addref/release so i guess it will be easy to reproduce the bug. If you don't I will send you a complete example.
Advertisement
The compiler doesn't allow you to declare variables as object handles if the object type doesn't have the addref/release behaviours. I guess in this case I missed verifying that the behaviours are really registered.

It is allowed to register addref/release behaviours for objects that have been registered with a size of 0. This can be used to prevent the script language from declaring local variables of that type, but still allow the script language to store handles to the type. If you don't register addref/release behaviours for a type of size 0, then the object can only be used as a registered property, or returned by reference from a registered function. The script won't be able to store the type in any variable, not pass it to as an argument to another function.

I'll look into this bug, and come back as soon as possible.

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

Bug fix:

1. Add this statement to asCBuilder::CreateDataTypeFromNode() at line 1080 (after the if( n->tokenType == ttConst ) statement block):

asCScriptNode *typeNode = n;

2. Alter the line on 1152 to:

file->ConvertPosToRowCol(typeNode->tokenPos, &r, &c);

I'm testing your other bug reports now.

Note, that you will now get asINVALID_DECLARATION when trying to register your application function without having the addref/release behaviours registered. If you don't intend to use the addref/release functionality, you could register behaviour functions that don't do anything.

Thanks,
Andreas

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

This is exactly what I do: by default I register 2 callbacks that don’t do anything. The problem is that after that I may want to register my custom 2 handles for addref/release. The script engine doesn’t allow reregistering these handles again and exits with error. So maybe it is better to allow changing the behaviors (of course prior to compilation).
Wouldn't it be easier to just register the true addref/release methods from the start? What makes it easier for you to first register a default pair of functions and then try to change them?

In my opinion it is an error to try to altered the registered behaviour functions, which is why it reports an error.

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

I'm encapsulating all the scripting system through interfaces so theoretically I can support multiple scripting languages at the same time. I registered the class with a call (like iScriptEngine::RegClass(const char *class_name, const int size)) and never bothered to add addref/release behaviors for the most classes since i've registered some default ones in RegClass function. After this call I want to add some real addref/release for some classes. But I cannot since the internal implementation of the RegClass added some dummy ones.

Anyway the problem is solved since I've included a parameter in the RegClass (const bool add_default_behavior = true). So I will set this param on false for classes with real addref/release.

This is not a problem for me anymore. A problem is the memory allocations made by the script runs. Now, I'm using multiple DLLs and one allocation in one lib space cannot be freed in another DLL. Having the angelscript statically linked to a dll and trying to delete an object (in Release when ref count reaches 0) in another dll cause heap corruption. The object is allocated by angelscript when entering the script scope (block) in script engine dll memory space, and deleted in another DLL that registered the class.

I've resolved this problem but it will be nice if I can hook my own allocation functions with the angel script. I can run my custom allocator and memory leak detection mechanism for scripts, too. But that is not a priority for me right now.

Thanks
Licu
One of the reasons for the internal changes in AS 2.0.0 was to allow the registration of custom memory management functions, per object type. When I add this support you will simple register a couple of behaviour functions (alloc/free) for the type.

I'll try to complete this support soon.

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

This topic is closed to new replies.

Advertisement