Advertisement

Passing delegate by value to vararg parameter causes crash

Started by July 10, 2016 08:51 PM
2 comments, last by WitchLord 8 years, 4 months ago

Passing a delegate by value to a vararg parameter causes a crash.

The following code causes the crash in 2.31.1:


funcdef void Foo();

class Bar
{    
    void bar()
    {
        Print( "works\n" );
    }
}

void test()
{    
    dictionary foo;
    
    foo.set( "bar", Foo( Bar().bar ) );
    
    Foo@ pFoo;
    
    foo.get( "bar", @pFoo );
    
    pFoo();
}

dictionary::set's second parameter is ?& in, which fails to handle this case. Using @Foo instead of Foo causes it to work as expected.

A complete program that triggers this problem can be downloaded here: https://dl.dropboxusercontent.com/u/46048979/AS_FuncDefBug.rar

Generic functions taking ref objects for vararg parameters are a bit hard to deal with. Seems like they sometimes have their ref count incremented by the engine, but not always. Sometimes i'd double free one, and if i don't, i end up leaking a reference. Seems to be related to this problem.

Thanks for the detailed bug report. I'll investigate and fix this.

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. I don't think the reference counting issue is caused by the library itself, i found some incorrect reference handling issues in my code and fixed it. Seems good now.

OK. Thanks for letting me know.

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