Stack corruption when using funcdef and class property

Started by
3 comments, last by WitchLord 9 years, 2 months ago

When i call a funcdef that i retrieve from a class property, the stack is corrupted, causing a crash when the function accesses parameters passed to it.

This script code causes the problem:


funcdef void Callback( array<int>@ pArray );

class Class
{
	private Callback@ m_pCallback;
	
	Callback@ Callback
	{
		get const { return m_pCallback; }
	}
	
	Class( Callback@ pCallback )
	{
		@m_pCallback = @pCallback;
	}
}

void CallbackFn( array<int>@ pArray )
{
	uint uiLength = pArray.length(); //Crash occurs here
}

void test()
{
	Class instance( @CallbackFn );
	
	array<int> arr;
	
	instance.Callback( @arr );
}

Replacing the direct use of the property with the following does not cause any problems:


Callback@ pCallback = instance.Callback;
pCallback( @arr );

An example program that causes the bug is attached.

Advertisement

Thanks for narrowing it down to this simple case. I'll look into it and should have a fix available shortly.

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

I've fixed this bug in revision 2115.

Thanks,

Andreas

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

There is another issue with funcdefs and properties.

Give the following code:


namespace Ini
{
funcdef void ParserMessageCallback( const string& in szMessage );

class Parser
{
	private ParserMessageCallback@ m_MessageCallback = null;

        ParserMessageCallback@ MessageCallback
	{
		get const { return @m_MessageCallback; }
		set { @m_MessageCallback = value; }
	}
}
}

Attempting to set the MessageCallback on an instance fails:


void MessageCallback( const string& in szMessage )
{
...
}

Ini::Parser parser;
	
@parser.MessageCallback = @MessageCallback;

The compiler error given is:

No matching signatures to 'Parser::set_MessageCallback(::MessageCallback)'
Candidates are:
void Parser::set_MessageCallback(Ini::ParserMessageCallback@ value)

I tried this with a class in the global namespace, and it worked in that case, so this appears to be an issue with namespaces.

Nevermind, it turns out that the exact code that caused this had a funcdef with int parameters, but i tried to assign one with uint parameters.

it would be nice if the error message were clearer, though.

Thanks. I'll look into improving the error message to make it clear that the match wasn't found due to mismatch in the function pointer signature.

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