Advertisement

Problem at revision 350 when used with AS_MAX_PORTABILITY

Started by February 06, 2009 10:35 AM
6 comments, last by WitchLord 15 years, 9 months ago
Hi again, I'm having a problem since I updated to last svn revision. The builds using AS_MAX_PORTABILITY are getting an error -12 (asINVALID_TYPE) from asIScriptGeneric method SetReturnDWord. This code. No big mistery. error = gen->SetReturnDWord( (asDWORD)argument->integer ); assert( error >= 0 ); It's a win32 debug build. I can't get any sense of it and I don't know of anything that could be breaking it in my side, and it was working fine before. Could you confirm me if AS_MAX_PORTABILITY is working fine for you? Thnx in advance.
I've had no problems with 350 on Windows with functions that use SetReturnDWord(). How are the functions you're having trouble with registered?
Advertisement
asIScriptGeneric::SetReturnDWord() validates the return type of the registered function to make sure it is compatible with a DWORD. For example if you've registered the function to return a reference to an integer then SetReturnDWord() will fail with -12, as you should have used SetReturnAddress instead.

What is the function signature that you registered the function as?

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

Oh! I went looking for what function was the one triggering it to paste the registration here, and I found the return of that function is a bool. So it's the casting of the bool into the dword return what is not accepted. Changing the function to return an int skips the error. This is not a proper solution, tho, but should make clear to you where the problem is.

Being more specific. This is the problematic global function registration (the first one, I actually have lots returning bool):

static qboolean asFunc_FileExists( asstring_t *path ){	if( !path || !path->len )		return qfalse;	return ( trap_FS_FOpenFile( path->buffer, NULL, FS_READ ) != -1 );}static void asFunc_asGeneric_FileExists( void *gen ){	G_asGeneric_SetReturnInt( gen, 		asFunc_FileExists( (asstring_t *)G_asGeneric_GetArgAddress( gen, 0 ) ) );}// this is used to call the registration of the global function{ "bool G_FileExists( cString & )", asFunc_FileExists, asFunc_asGeneric_FileExists },

G_asGeneric_SetReturnInt and G_asGeneric_SetReturnInt are just C wrappers to asIScriptGeneric methods. Nothing differs there, just the names :)

Changing it to:
 { "int G_FileExists( cString & )", asFunc_FileExists, asFunc_asGeneric_FileExists },

Solves it (makes it fail on the next returning bool function).

So the question is now: Has asScriptGeneric::SetReturnBoolean been implemented? It didn't exist when I originally did this code.
Check what AS_SIZEOF_BOOL is for your platform. You should use the SetReturn function for the data type that's the same size. If you're having this problem, probably SetReturnByte().
I find angelscript has it to 1 for everything excepting macosx. Gonna try now. I guess there is no way to ask it to the library itself, right? May be a good idea to add it if there isn't.
Advertisement
Problem solved. Thanks again.
An alternative is to use GetReturnPointer(), like this:

static void asFunc_asGeneric_FileExists( asIScriptGeneric *gen ){  *(bool*)gen->GetReturnPointer() = asFunc_FileExists( (asstring_t *)G_asGeneric_GetArgAddress( gen, 0 ) );}


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