Posted: 25th Jul 2021 18:24
When returning a string pointer from a plugin function does AppGameKit destroy the pointer?

Strings created with CreateString must be deleted with DeleteString, but when returning a string pointer from my function I no longer have access to the pointer to destroy it because the function has returned, I globalised it and checked the pointer and it appears to have been cleared but could you please confirm what AppGameKit does with this buffer?

I'm getting random IMA's and am trying to track the cause and its looking like strings at this stage, I'v a bulk of function calls to a XML plugin (project loading routine) and its crashing out somewhere in the middle of these calls, a lot of string data is changing hands so it must be something in there.
Posted: 25th Jul 2021 18:52
From AGKCommonSwitch.h in Tier 2\apps\interpreter:

+ Code Snippet
case AGKI_PLUGIN_COMMAND:
...<snip>
		switch( pCommand->iReturnType )
		{
			case AGK_VARIABLE_INTEGER: m_pStack[ m_iStackPtr++ ].i = result.i; break;
			case AGK_VARIABLE_FLOAT: m_pStack[ m_iStackPtr++ ].f = result.f; break;
			case AGK_VARIABLE_STRING: 
			{
				m_pStrStack[ m_iStrStackPtr++ ].SetStr( result.s ); 
				delete [] result.s;
				break;
			}
		}
Posted: 25th Jul 2021 19:39
Thanks, I thought so.