• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
iraxef

Segfault when binding function which takes script-array param

11 posts in this topic

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
0

Share this post


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

Please try the latest revision and see if it helps.
0

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
0

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.

0

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.

0

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

0

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

0

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.

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0