Jump to content

  • Log In with Google      Sign In   
  • Create Account


BlackMoons

Member Since 17 Feb 2003
Offline Last Active Jul 26 2014 02:22 PM
-----

Topics I've Started

Line numbers for non-terminated string literal?

13 July 2014 - 03:43 PM

With the following code:

string foo = "
string bar = "Hello";
string bar2 = "World";

Angelscript throws a compile error of "non-terminated string literal" line 3 char 21

 

When it really should be throwing the error on line 1 char 14.

 

In much larger more complex files, it seems to always throw the error on the very last string literal regardless where it happens in the file and does not complain about anything else. Makes it kinda hard to find out what string literal you messed up on.

 


Is this assignment operator correct?

19 April 2014 - 12:33 AM

Is the following assignment operator correct?

I am mainly wondering about if rhs should be released? Since its a const object I can't, Or does the fact it is passed by ref instead of handle means the ref count was not incremented?

 

Is it better to take the rhs by handle to avoid the copy of the object?

class ObjectPicker : public ScriptRef
{
public:
	std::vector<ObjectPick> mObjects;
	ObjectPicker & ScriptAssign(const ObjectPicker & rhs)
	{
		mObjects = rhs.mObjects;
		AddRef(); // because of returning object
		return *this;
	}
};
(ObjectPicker is registered as asOBJ_REF)
r = scriptEngine->RegisterObjectMethod("ObjectPicker", "ObjectPicker @ opAssign(const ObjectPicker &in)", asMETHOD(ObjectPicker,ScriptAssign), asCALL_THISCALL); assert( r >= 0 );

Removing a callback

08 April 2014 - 01:28 PM

Hi. I have the following Angelscript code:

class ElectricLightSource
{
    void Interact(User @ user)
    {
        if (mOwner.GetObject().mState > 0)
        {
            gObjects.RemovePowerDraw(PowerFunction(this.UpdatePower));
            mOwner.GetObject().mState = 0;
        }
        else
        {
            gObjects.AddPowerDraw(PowerFunction(this.UpdatePower));
            mOwner.GetObject().mState = 2; // Start with power off;
        }
    }
}

And the C++ functions called are:

...
    r = scriptEngine->RegisterFuncdef("void PowerFunction()"); assert( r >= 0 );
    r = scriptEngine->RegisterObjectMethod("ObjectManager", "void AddPowerDraw(PowerFunction@)", asMETHOD(ObjectManager,AddPowerDraw), asCALL_THISCALL); assert( r >= 0 );
    r = scriptEngine->RegisterObjectMethod("ObjectManager", "void RemovePowerDraw(PowerFunction@)", asMETHOD(ObjectManager,RemovePowerDraw), asCALL_THISCALL); assert( r >= 0 );
...
std::vector<asIScriptFunction*> mPowerCallbacks;
...

void ObjectManager::AddPowerDraw(asIScriptFunction* function)
{
	mPowerCallbacks.push_back(function);
}
void ObjectManager::RemovePowerDraw(asIScriptFunction* function)
{
	std::vector<asIScriptFunction*>::iterator cur = mPowerCallbacks.begin(), end = mPowerCallbacks.end();
	for (; cur != end; cur++)
	{
		if (*cur == function)
		{
		--end;
		if (cur != end)
			*cur = *end;
		mPowerCallbacks.pop_back();
		return;
		}
	}
}

My problem is that the remove call, "if (*cur == function)" never passes. What am I doing wrong?


Function Reference counting

23 February 2014 - 04:28 PM

Hi. I am wondering how its recommended I deal with function ref counts. I am getting some cleanup errors on ref

counts.

(0:0) Object {107}. GC cannot destroy an object of type '_builtin_function_' as it can't see all references. Current ref count is 1.
(0:0) The builtin type in previous message is named 'InventoryClosedCallback'

Mainly I am wondering if 'module->GetFunctionByName()' adds a refcount to the function it returns?

Should I be addref'ing what it returns before storing it? Should I release on program cleanup? Or should I just let angelscript handle all the ref counts for functions and not touch them?

 

Currently I have:

asIScriptModule *module = scriptEngine->GetModule(moduleNameAscii.c_str());
asIScriptFunction *func = module->GetFunctionByName(functionNameAscii.c_str());
func->AddRef();
AddScriptCallback(func)

AddScriptCallback just adds it to a vector of asIScriptFunction*, who get release() called on them on program exit (Before anglescript is cleaned up however)

if I remove the func->AddRef, angelscript crashes in asCModule::~asCModule()  Line 68, called from      asCScriptEngine::~asCScriptEngine()  Line 559 (ie, as angelscript shuts down)

It also appears that when Angelscript calls a function similar to AddScriptCallback that the func does indeed have 1 extra ref. I assume that is because I pass it by @ handle.

void Player::AddItemCallback(ScriptCallback::CallbackSource callbackSource,  asIScriptFunction *func, unsigned int callbackData)
{
	ScriptCallback newCallback;
	newCallback.mCallback = func;
	newCallback.mCallbackData = callbackData;
	newCallback.mCallbackSource = callbackSource;
	mScriptCallbacks.Add(newCallback);
}

r = scriptEngine->RegisterObjectMethod("Player", "void AddItemCallback(CallbackSource,ItemCallback @,uint)", asMETHOD(Player,AddItemCallback), asCALL_THISCALL); assert( r >= 0 );

that results in angelscript not complaining about any GC cleanup errors.


asIScriptObject::Release return code

25 September 2013 - 05:22 PM

Hi. Today I managed to accidentally access a null handle in a Angelscript destructor called by my C++ program calling asIScriptObject::Release() on a script class object passed from Angelscript to C++.

 

The problem? It never logged anything in my error logs.

I go and check Release()'s return code and its 0.

 

Shouldn't it be returning asEXECUTION_EXCEPTION? And then I could handle it the same way as when Context->Execute() hits a null handle?


PARTNERS