I'm trying to make an engine similar to how unity does it where I can compile the engine on the other OS's and be able to use scripting to make it work. So my classes I want to look like this.
class TestLevel : AffinityScript {
void Init() {
}
void Start() {
}
void Update() {
}
}
However when calling the Start method I get a null reference pointer.
Here's some of the code.
int r;
asIScriptModule* mod = this->m_pEngine->GetModule(filename.c_str(), asGM_ONLY_IF_EXISTS);
r = this->m_bBuilder.StartNewModule(this->m_pEngine, filename.c_str()); assert(r >= 0);
r = this->m_bBuilder.AddSectionFromFile((filename + ".as").c_str()); assert(r >= 0);
r = this->m_bBuilder.BuildModule(); assert(r >= 0);
Script* script = new Script();
script->Module = filename;
mod = this->m_pEngine->GetModule(filename.c_str(), asGM_ONLY_IF_EXISTS);
asIObjectType *type = 0;
int tc = mod->GetObjectTypeCount();
for(int n = 0; n < tc; n++) {
bool found = false;
type = mod->GetObjectTypeByIndex(n);
int ic = type->GetInterfaceCount();
for(int i = 0; i < ic; ++i) {
if(strcmp(type->GetInterface(i)->GetName(), "AffinityScript") == 0) {
found = true;
break;
}
}
if(found == true) {
script->m_pType = type;
break;
}
}
if(script->m_pType == 0) {
delete script;
return;
}
script->InitMethod = type->GetMethodByDecl("void Init()");
script->StartMethod = type->GetMethodByDecl("void Start()");
script->DrawMethod = type->GetMethodByDecl("void Draw()");
script->UpdateMethod = type->GetMethodByDecl("void Update()");
script->ExitMethod = type->GetMethodByDecl("void OnExit()");
this->m_mScripts[this->m_mScripts.size()] = script;
if(itr->second->StartMethod != 0) {
asIScriptContext *ctx = PrepareContextFromPool(itr->second->StartMethod);
ExecuteCall(ctx);
ReturnContextToPool(ctx);
}
asIScriptContext *ctx = 0;
if(this->m_vContexts.size()) {
ctx = *this->m_vContexts.rbegin();
this->m_vContexts.pop_back();
}else{
ctx = this->m_pEngine->CreateContext();
}
int r = ctx->Prepare(func); assert(r >= 0 );
return ctx;
Of course I'm borrowing some code from the Game sample to get this working until I come up with my own solution but the assert function happens at int r= ctx->Prepare(func);
Edit: I forgot to mention the null reference happens when taking away the assert./
Edit2: Actually it's happening WITH the assert now.
Edit3: I have my program dumping compile errors to a file and here's the contents
Edit4: I did a bit of research on it and the engine wants me to use ctx->SetObject(); but I don't want to attach a script to an object in particular is there a way to call the script without it?
Exception: Null pointer access
Function: 04898AC0
Line: 0
Any ideas?