ASSERT triggered when converting

Started by
4 comments, last by gjl 5 years, 7 months ago

A strange ASSERT is triggered when trying to cast an object that has multiple opCast operators for differents types:

2>  Assertion failed: func->returnType.GetTokenType() == ttVoid && func->parameterTypes.GetLength() == 1 && func->parameterTypes[0].GetTokenType() == ttQuestion, file ..\..\source\as_scriptengine.cpp, line 4918

Having a look at the code it seems this assertion is not valid and should be replaced by an if() statement - otherwise it means that you cannot implement the opCast method with different return types.


	// Look for ref cast behaviours
	asCScriptFunction *universalCastFunc = 0;
	asCObjectType *from = reinterpret_cast<asCObjectType*>(fromType);
	for( asUINT n = 0; n < from->methods.GetLength(); n++ )
	{
		asCScriptFunction *func = scriptFunctions[from->methods[n]];
		if( func->name == "opImplCast" ||
			(!useOnlyImplicitCast && func->name == "opCast") )
		{
			if( func->returnType.GetTypeInfo() == toType )
			{
				*newPtr = CallObjectMethodRetPtr(obj, func->id);
				// The ref cast behaviour returns a handle with incremented
				// ref counter, so there is no need to call AddRef explicitly
				// unless the function is registered with autohandle
				if( func->sysFuncIntf->returnAutoHandle )
					AddRefScriptObject(*newPtr, toType);
				return asSUCCESS;
			}
           // FIXME: check if this is a universal cast operator before storing it instead of asserting
			else if(func->returnType.GetTokenType() == ttVoid &&
                func->parameterTypes.GetLength() == 1 &&
                func->parameterTypes[0].GetTokenType() == ttQuestion )
			{
				universalCastFunc = func;
			}
		}
	}

I have tested the fix above and it seems to be causing no issues (and actually I think it fixes problems in case no appropriate cast is found). What do you think?

Advertisement

Thanks for the report. I'll look into this and have it fixed.

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

Great, thanks!

Your solution is correct.

I've checked in this in revision 2539.

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

Thanks!

 

This topic is closed to new replies.

Advertisement