Jump to content
  • Advertisement
Sign in to follow this  
iraxef

Can't allocate script array with an exception on context

This topic is 1463 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

I'm seeing an assert trigger in the following situation:

CScriptArray* MyFunction(const std::string& name, MyAppType* foo)
{
    asIObjectType* objectType = ...;

    if ( name.empty() )
    {
        asGetActiveContext()->SetException("Please provide a non-empty name");

        CScriptArray* scriptArray = CScriptArray::Create(objectType);
        assert( NULL != scriptArray ); // this asserts

        return scriptArray;
    }

    ...
}

What I'd prefer is that the function returns, but then I see my script exception (via whatever means I'm using to catch/display them).

 

If I allocate the array first, and then set the exception, there is no assert:

CScriptArray* MyFunction(const std::string& name, MyAppType* foo)
{
    asIObjectType* objectType = ...;

    if ( name.empty() )
    {
        CScriptArray* scriptArray = CScriptArray::Create(objectType);
        assert( NULL != scriptArray ); // this does not assert

        asGetActiveContext()->SetException("Please provide a non-empty name");

        return scriptArray;
    }

    ...
}

I can easily work around this (perhaps I should be returning NULL anyway since I've already set the script exception..) but FYI.

Edited by iraxef

Share this post


Link to post
Share on other sites
Advertisement

If I understand what you're trying to do, you shouldn't create the array since you already detected an error condition. Instead you should just return null.

 

 

On the other hand, the creation of the array shouldn't fail just because you've set an exception on the current context. I'll need to make some adjustments in the CScriptArray add-on to handle this scenario better. 

Share this post


Link to post
Share on other sites

I see what you mean:

	// It's possible the constructor raised a script exception, in which case we
	// need to free the memory and return null instead, else we get a memory leak.
	if( ctx && ctx->GetState() == asEXECUTION_EXCEPTION )
	{
		a->Release();
		return 0;
	}

	return a;

I guess you could check whether the context had an exception before the ctor was called... but then what if the ctor added another exception? Do you have any way to check whether there are now 2 exceptions?

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!