i have an entity class with angelscript engines and contexts as member variables. however when this class is apart of a vector array with more than one entity it crashes with a seg fault at the context preparing before executing,
Example code:
class test{
private:
asIScriptEngine *engine = asCreateScriptEngine();
asIScriptModule *ScriptModule;
asIScriptFunction *AngelUpdate;
asIScriptContext *ctx;
CScriptBuilder builder;
public:
test(){
builder.StartNewModule(engine, "MyModule");
builder.AddSectionFromFile("test.as");
builder.BuildModule();
ScriptModule = engine->GetModule("MyModule");
AngelUpdate = ScriptModule->GetFunctionByDecl("void main()");
ctx = engine->CreateContext();
ctx->Prepare(AngelUpdate);
ctx->Execute();
}
~test(){
ctx->Release();
engine->ShutDownAndRelease();
}
void update(){
ctx->Prepare(AngelUpdate);
ctx->Execute();
}
};
int main()
{
std::vector<test> entityvector{};
entityvector.emplace_back();
//one more emplace and there will be a crash.
while(true)
{
entityvector[0].update();
}
return 0;
}
strangely having multiple objects separate from a vector does not cause this crash.
this is kinda demotivating and im thinking of just moving to godot at this point xd