Sign in to follow this  
Solokiller

Stack corruption when using funcdef and class property

Recommended Posts

Solokiller    868

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.

Share this post


Link to post
Share on other sites
Solokiller    868

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.

Edited by Solokiller

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