Advertisement

Segfault when binding function which takes script-array param

Started by January 28, 2014 02:01 AM
10 comments, last by iraxef 10 years, 10 months ago

I'm trying to bind a C++ function which takes a script-array param. Following the example in the string add-on's utils, I've got the following (in C++):


namespace
{
    void Foo(const CScriptArray& arr, MyClass* sprite)
    {}
}

scriptEngine.RegisterObjectMethod("MyClass", "void Foo(const array<Vector2> &in)", asFUNCTION(Foo), asCALL_CDECL_OBJLAST);

I'm getting a segfault at the following location:


	asSSystemFunctionInterface &operator=(const asSSystemFunctionInterface &in)
	{
		func               = in.func;

Am I registering the function incorrectly? I'm using: SDK 2.28.1 WIP - 2014/01/23

Thank you very much.

UPDATE:

Please note that if I specify the array param as: const array<string> &in, I don't experience the issue. Vector2 above is an application-registered value type.

This sounds very much like the bug I fixed yesterday in revision 1821.

Please try the latest revision and see if it helps.

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

Thank you very much for the quick reply.

I'm trying revision 1823 and I'm still seeing the issue. (I confirmed via http://sourceforge.net/p/angelscript/code/1821/ that I seem to have the updated code in as_scriptengine.cpp).

It looks like the fix in revision 1821 was in RegisterObjectProperty() and I'm in RegisterObjectMethod(). (Don't know if that's helpful)

UPDATE:

I'm also consistently experiencing the crash with the param as: const array<float> &in. Though it's repeatedly OK with: const array<string> &in

Thanks. I'll investugate this in detail later today.

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

It appears that const array<mynamespace::Vector2> &in also works fine when registered as a global function.

Advertisement

I'll soon have the time to investigate this, but I think the fix will be to do a similar change in RegisterObjectMethod as what was done in RegisterObjectProperty in revision 1821.

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 the backtrace (for registering the param as: const array<float> &in):


asSSystemFunctionInterface::operator=(const asSSystemFunctionInterface & in)  Line 114 + 0x6 bytes   C++
asSSystemFunctionInterface::asSSystemFunctionInterface(const asSSystemFunctionInterface & in)  Line 110  C++
asCScriptEngine::GenerateNewTemplateFunction(asCObjectType * templateType, asCObjectType * ot, asCScriptFunction * func, asCScriptFunction * * newFunc)  Line 3725 + 0x3e bytes  C++
asCScriptEngine::GetTemplateInstanceType(asCObjectType * templateType, asCArray<asCDataType> & subTypes)  Line 3416 + 0x18 bytes C++
asCBuilder::CreateDataTypeFromNode(asCScriptNode * node, asCScriptCode * file, asSNameSpace * implicitNamespace, bool acceptHandleForScope, asCObjectType * currentType)  Line 4632 + 0x16 bytes C++
asCBuilder::ParseFunctionDeclaration(asCObjectType * objType, const char * decl, asCScriptFunction * func, bool isSystemFunction, asCArray<bool> * paramAutoHandles, bool * returnAutoHandle, asSNameSpace * ns, asCScriptNode * * listPattern)  Line 1035 + 0x47 bytes  C++
asCScriptEngine::RegisterMethodToObjectType(asCObjectType * objectType, const char * declaration, const asSFuncPtr & funcPointer, unsigned long callConv)  Line 2654 + 0x34 bytes    C++
asCScriptEngine::RegisterObjectMethod(const char * obj, const char * declaration, const asSFuncPtr & funcPointer, unsigned long callConv)  Line 2613 + 0x23 bytes    C++

In GenerateNewTemplateFunction(), the failure is in assigning to sysFuncIntf:


// TODO: template: Must be careful when instanciating templates for garbage collected types
//                 If the template hasn't been registered with the behaviours, it shouldn't
//                 permit instanciation of garbage collected types that in turn may refer to
//                 this instance.

func2->inOutFlags = func->inOutFlags;
func2->isReadOnly = func->isReadOnly;
func2->objectType = ot;
func2->sysFuncIntf = asNEW(asSSystemFunctionInterface)(*func->sysFuncIntf);

func->name is "factstub".

func->sysFuncIntf is null. So *func->sysFuncIntf is creating a bad reference (?).

Unfortunately I'm not able to reproduce this problem.

It is definitely a bug in AngelScript as it shouldn't be calling GenerateNewTemplateFunction for a function with the name 'factstub'. It appears that there is some condition that makes it try to copy an already existing template instance.

Can you show me everything that you're registering with the engine up until the call that crashes? You can call the helper function WriteConfigToFile() just before the call that crashes and post the content from the file here.

You'll find WriteConfigToFile in the add_on/scripthelper/scripthelper.h/cpp

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

Requested file emailed to you. I had tried to make the above line conditional (to avoid the bad assignment) and then I ran into another issue in:


asCScriptFunction *asCScriptEngine::GenerateTemplateFactoryStub(asCObjectType *templateType, asCObjectType *ot, int factoryId)
{
    ....

    // Skip the first parameter as this is the object type pointer that the stub will add
func->parameterTypes.SetLength(factory->parameterTypes.GetLength()-1);
}

factory->parameterTypes.GetLength() was 0, so SetLength() tried to do a massive Allocate() which failed.

This topic is closed to new replies.

Advertisement