Jump to content
  • Advertisement
Sign in to follow this  
Solokiller

Problem with named parameters and object behaviors

This topic is 987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It seems that object behaviors have a problem with named arguments. Attempting to use them causes a crash due to a null pointer.

Specifically, the problem is that the behavior's function doesn't have a valid parameterNames array. I've isolated the problem to the asCScriptEngine::AddBehaviourFunction method:

asCScriptFunction *f = asNEW(asCScriptFunction)(this, 0, asFUNC_SYSTEM);
if( f == 0 )
{
	asDELETE(newInterface, asSSystemFunctionInterface);
	return asOUT_OF_MEMORY;
}

asASSERT(func.name != "" && func.name != "f");
f->name           = func.name;
f->sysFuncIntf    = newInterface;
f->returnType     = func.returnType;
f->objectType     = func.objectType;
if( f->objectType )
	f->objectType->AddRefInternal();
f->id             = id;
f->isReadOnly     = func.isReadOnly;
f->accessMask     = defaultAccessMask;
f->parameterTypes = func.parameterTypes;
f->inOutFlags     = func.inOutFlags;
for( n = 0; n < func.defaultArgs.GetLength(); n++ )
	if( func.defaultArgs[n] )
		f->defaultArgs.PushLast(asNEW(asCString)(*func.defaultArgs[n]));
	else
		f->defaultArgs.PushLast(0);

AddScriptFunction(f);

The parameterNames variable is never copied over, so when the compiler tries to access it, it gets a null string from the array, which then triggers the exception when it is compared to a named argument.

 

This may also be a problem with regular methods, i haven't tested that. Presumably that is the case though.

Share this post


Link to post
Share on other sites
Advertisement

The smallest program that still reproduces it requires a change to the array constructor that constructs an array of a given number of elements. The parameters need to be named:

r = engine->RegisterObjectBehaviour("array<T>", asBEHAVE_FACTORY, "array<T>@ f(int&in, uint count, const T &in value)", asFUNCTIONPR(CScriptArray::Create, (asIObjectType*, asUINT, void *), CScriptArray*), asCALL_CDECL); assert( r >= 0 );

The following script code will then cause a null pointer exception:

void test()
{
	array<string> a( 10, value: "foo" );
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!