Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Segfault when binding function which takes script-array param


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 iraxef   Members   -  Reputation: 330

Like
0Likes
Like

Posted 27 January 2014 - 08:01 PM

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.


Edited by iraxef, 27 January 2014 - 08:10 PM.


Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3290

Like
0Likes
Like

Posted 27 January 2014 - 08:21 PM

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

#3 iraxef   Members   -  Reputation: 330

Like
0Likes
Like

Posted 27 January 2014 - 08:45 PM

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).



#4 iraxef   Members   -  Reputation: 330

Like
0Likes
Like

Posted 27 January 2014 - 09:01 PM

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


Edited by iraxef, 27 January 2014 - 09:25 PM.


#5 Andreas Jonsson   Moderators   -  Reputation: 3290

Like
0Likes
Like

Posted 28 January 2014 - 04:55 AM

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

#6 iraxef   Members   -  Reputation: 330

Like
0Likes
Like

Posted 28 January 2014 - 10:48 AM

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



#7 Andreas Jonsson   Moderators   -  Reputation: 3290

Like
0Likes
Like

Posted 28 January 2014 - 12:43 PM

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

#8 iraxef   Members   -  Reputation: 330

Like
0Likes
Like

Posted 28 January 2014 - 02:12 PM

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 (?).



#9 Andreas Jonsson   Moderators   -  Reputation: 3290

Like
0Likes
Like

Posted 28 January 2014 - 03:20 PM

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

#10 iraxef   Members   -  Reputation: 330

Like
0Likes
Like

Posted 28 January 2014 - 03:38 PM

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.



#11 Andreas Jonsson   Moderators   -  Reputation: 3290

Like
0Likes
Like

Posted 28 January 2014 - 06:27 PM

Thanks a lot for the file

 

I managed to reproduce the problem with the following test:

 

engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
engine->SetMessageCallback(asMETHOD(COutStream, Callback), &out, asCALL_THISCALL);
 
RegisterScriptArray(engine, false);
 
engine->SetDefaultNamespace("gfx");
 
engine->RegisterObjectType("GfxSprite", 0, 1);
engine->RegisterObjectMethod("GfxSprite", "array<gfx::GfxSprite@>@ GetChildren() const", asFUNCTION(0), asCALL_GENERIC);
 
r = engine->RegisterObjectMethod("GfxSprite", "void Foo(const array<float> &in)", asFUNCTION(0), asCALL_CDECL_OBJLAST);
 
engine->Release();

 

The condition that hit the bug was that you were registering two (or more) methods on the same type that had arrays as parameters or return types + that you were using namespaces. In this particular situation the code picked the wrong type as the template type and instead tried to create the new template instance based on the previous template instance.

 

I've fixed the bug in revision 1826.

 

I also took the opportunity to change the code so that you no longer need to prefix the sub-type in the array with the namespace. :)


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

#12 iraxef   Members   -  Reputation: 330

Like
0Likes
Like

Posted 28 January 2014 - 08:42 PM

Confirmed (with revision 1826) that the desired C++ function binds now without issue. Thank you!!!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS