Hi all!
I've been writing a class called "actorList", which is basically a list of all actors. I'm not using the array type because I want to extend this type to support some additional features like filtering, ordering, etc.
"Actor" is an interface. there are different types of actors in my game, such as componentActor, Light and Sound. ALL of the derived classes of Actor have turned off garbage collection (I distrust the garbage collector >_>. The script side only has restricted entry points and is not allowed to instantiate these classes. Hence, I decided to turn garbage collection off.)
class actorList{
public:
int getSize(){
return this->actors.size();
};
Actor *get(int index){
return this->actors[index];
};
void Add(Actor *a){
this->actors.push_back(a);
}
void Clear(){
this->actors.clear();
}
actorList(std::vector<Actor *>actors){
this->actors = actors;
}
actorList(const actorList &other){
this->actors = other.actors;
}
actorList(){};
~actorList(){};
private:
std::vector<Actor *>actors;
};
I've been trying to bind " Actor *get(int index)" and I'm not able to do it :/
--------------------------------------------------------------------------------------------------------------------------------------------------
I've been binding the function this way:
//function is Actor *get(int index)
actorListDef.addMethod(AS_ObjMethodDef("Actor@ Get(int index)",
AS_FunctionDef(asMETHODPR(actorList, get, (int index), Actor*), asCALL_THISCALL )));
If I access it from the script side like so:
Actor @actor;
//this statement makes sense right? *p = *q;
@actor = @allActors.Get(i);
or like so:
Actor @actor;
//*p = q I don't know what this means
@actor = allActors.Get(i);
It goes and crashes at as_engine.cpp at line number 3333. These are the surrounding lines:
void asCScriptEngine::CallObjectMethod(void *obj, int func)
{
asCScriptFunction *s = scriptFunctions[func]; <-- this is where it crashes
asASSERT( s != 0 );
CallObjectMethod(obj, s->sysFuncIntf, s);
}
Here, the "this" appears to have been freed and has been set to Visual Studio's "memory freed" debug pattern - 0xfeeefeee
- this 0xfeeefeee {isPrepared=??? memoryMgr={cs={cs={DebugInfo=??? LockCount=??? RecursionCount=??? ...} } ...} ...} asCScriptEngine *
//------------------------------------------------------------------------------------------------------------------------------------------
I also tried binding it this way:
void get(int index, Actor **a){
*a = this->actors[index];
}
Here's how I bound it to the script side:
actorListDef.addMethod(AS_ObjMethodDef("void Get(int index, Actor &out)",
AS_FunctionDef(asMETHODPR(actorList, get, (int index, Actor **a), void), asCALL_THISCALL )));
because the documentation said this:
&out : A reference to an unitialized value is passed to the function. When the function returns the value is copied to the true reference. The argument expression is evaluated only after the function call. This is the best way to have functions return multiple values.
But on doing this, it says "No default constructor for object of type 'Actor'. " as well as "There is no copy operator for the type 'Actor' available." , and then the usual unable to Prepare, unable to Exexute.
Help, Anyone? I have no clue as to what I'm doing wrong / what I'm supposed to do.
Thanks
~Bollu