Advertisement

Arrays are broken in new version.

Started by March 31, 2011 02:19 PM
7 comments, last by WitchLord 13 years, 7 months ago
In the latest version of angelscript when i declare an array object i keep getting this error:

"The application doesn't support the default array type."

the way i am declaring it is like so int[] a; It has been a while since i updated my angelscript version, so maybe some stuff have changed in the past few years since i last updated.
The built-in array type has been removed in favor of user-registrable arrays.

The script array add-on that comes with the sdk is fully compatible with the previously built-in array. You just need to register it with a call to:


RegisterScriptArray(engine, true);


Regards,
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

Advertisement
Thanks. It is now working.

I have another question, now in this version every time i exit my application it ends abruptly and throws an exception on this function in the file as_scriptengine.cpp. The older version i had was fine.

int asCScriptEngine::CallObjectMethodRetInt(void *obj, int func)
{
asCScriptFunction *s = scriptFunctions[func];
asSSystemFunctionInterface *i = s->sysFuncIntf;
The engine is obviously trying to call some method as part of the clean-up. Probably it's calling Release() on some object that was still in the GC. Make sure you don't destroy any reference counted objects before the ref counter reaches 0.

I would need to know more about your implementation to give you a more precise answer. Can you check the name of the function and the object type that the engine is trying to call? The asCScriptFunction object has this information.

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

The thing i do not seem to understand is that every time i update the library to the new version, something else is broken. It is getting very annoying. I mean i am spending most of my time trying to fix angelscript issues that used to work that no longer works. The way my implementation works is that i created several instances of the same classes but i have AddRef on all of them, so when the class destructor of the object get call it calls Release first before deleting the object. So by the time all the objects are release the ScriptObject should be gone by then. Like i said, it use to work before with no issues.

One of the weird things i notice is that when i call engine->CreateContext, it automatically called AddRef and set the reference count to 2 which should be 1. I am not sure if that is the problem but you can try looking into it.
I try very hard to avoid breaking stuff that was previously working, and have a very large suite of test cases that I make sure all pass before I release a new version. Of course, even with that there are inevitably times when things break, but it shouldn't be that often. If you're having trouble with every update, then you must be doing things differently from what I had envisioned and because of that I do not have the proper tests in place to avoid breaking what you're doing.

I'm sorry but I didn't understand exactly how you've designed your application.

You say you create several instances of the same class, but then you have a destructor calling the release method. The destructor calls the release method on what? What is the relation between the classes?

You say addref is called when you call engine->CreateContext. But addref is called on what? When engine->CreateContext is called AngelScript shouldn't be calling addref on anything. If that is happening, something is seriously wrong.

I want to help you figure out what is wrong, but I need more information to do that.

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


Thanks WitchLord.

But I have the similar problem too.
I implement my private string class, and it works fine with older version.
But when I upgrade to 2.20.2, it raise some strange excetion in Release().
If I re-arrange the C-class member, the exception will disappear.

I couldn't reproduce this problem with CScriptString.

May I send the testing program to you ?

Yes, please send it to me. If I can reproduce the problem I can have it fixed.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

I found loboWu's problem after he sent the code to me. While he was using his own string types, the problem can be reproduced with the standard add-ons as well.


Let's say we have a class like this:




class CTestObj
{
public:

std::string b;

}




If the application registers the string type as a reference counted wrapper that holds the std::string as a member, similarly to how the CScriptString add-on works, the application must not register the member b as being of that type. This is because AngelScript may need to call the AddRef/Release behaviours on the CScriptString type in order to guarantee the lifetime of the object for some operations. If that is done, the AddRef/Release behaviour will end up changing memory that doesn't belong to the string b.

The AddRef/Release behaviour is usually only called when a method of the object that returns a reference is called, so you might get away without any problems if this never happens.



This is change from previous versions of AngelScript, because script functions and methods weren't allowed to return references before, so AngelScript didn't need to make this extra call to AddRef/Release to secure the lifetime of the returned reference (as it is assumed the application developer knows not to return references to memory that will be invalid as soon as the function returns).


Regards,

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 topic is closed to new replies.

Advertisement