Jump to content
  • Advertisement
Sign in to follow this  
iraxef

Segfault when binding function which takes script-array param

This topic is 2085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
This sounds very much like the bug I fixed yesterday in revision 1821.

Please try the latest revision and see if it helps.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!