Hmm... yes, I'm really stumped by this; your code looks good. I've got it to init and execute up to the main update method but still get a crash here:
Quote:
Engine.exe!asCScriptObject::`vcall'{0}'() + 0x2 bytes C++
Engine.exe!CallThisCallFunction(const void * obj=0x09593018, const unsigned long * args=0x095cfbe0, int paramSize=0, unsigned int func=5018058) Line 1054 C++
Engine.exe!CallSystemFunction(int id=18, asCContext * context=0x09592f00, void * objectPointer=0x00000000) Line 212 + 0x1b bytes C++
> Engine.exe!asCContext::ExecuteNext() Line 1960 + 0x12 bytes C++
Engine.exe!asCContext::Execute() Line 1004 + 0x8 bytes C++
Here is my AS object code:
_ctx = contextPool->AquireContext(); if(!_ctx) throw ("Some wacky scripting error occured..."); asIScriptEngine *Engine = contextPool->GetEngine(); int typeID = Engine->GetModule(0)->GetTypeIdByDecl( class_decl ); if( typeID < 0 ) { _ctx->destroyed = true; } asIObjectType* type = Engine->GetObjectTypeById( typeID ); _ctx->objectType = type; _ctx->function_id = type->GetMethodIdByDecl( method_decl ); if( _ctx->function_id < 0 ) { _ctx->script_status = asEXECUTION_SUSPENDED; _ctx->suspend = INFINITE_SUSPEND; } _ctx->SetClassName( class_decl );//construct object // create object at position int funcId = _ctx->objectType->GetFactoryIdByDecl ( contextPool->ClassDeclToCtor( _ctx->GetClassName().c_str(), "(const Vector2 &in)" ) ); if( funcId < 0 ) { // use default constructor CreateObject(); } else { contextPool->PushInstance( this ); _ctx->context->Prepare( funcId ); Vector2 test(222,333); *(Vector2**)_ctx->context->GetAddressOfArg(0) = &test; //int r = _ctx->context->SetArgObject(0, &test); _ctx->context->Execute(); _ctx->object = _ctx->context->GetAddressOfReturnValue(); //_ctx->context->GetReturnObject(); contextPool->PopInstance(); } return (asIScriptObject*)_ctx->object;//update object _ctx->context->Prepare( _ctx->function_id ); contextPool->PushInstance( this ); _ctx->context->SetObject( _ctx->object ); _ctx->script_status = _ctx->context->Execute(); //<----- here contextPool->PopInstance(); return _ctx->script_status;
Stepping through the code shows everything seems to work properly 'till the update method.. Also, forcing the default object ctor via CreateObject() ( which is just this: )
_ctx->object = contextPool->GetEngine()->CreateScriptObject( _ctx->objectType->GetTypeId() );
return (asIScriptObject*)_ctx->object;
Works fine. ?
Also, yes the above was a typo. ;) However Context::object is a void* and I still end up casting it the same way. Is this wrong? -Also just a note, "return (asIScriptObject*)_ctx->object;" is never actually used yet.
[Edited by - arpeggiodragon on September 19, 2010 10:54:21 PM]