This does not happen in the tutorial example, and I cannot find the difference in my code from it.
Init:
bool scriptManager::onInit()
{
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
if(engine == 0)
{
SLog("Failed to create script engine.");
return false;
}
engine->SetCommonMessageStream((asOUTPUTFUNC_t)printf, 0);
RegisterScriptString(engine);
//REGISTER ALL MAIN FUNCTIONS ETC HERE!!
engine->RegisterGlobalFunction("void Log(string &in)", asFUNCTION(scripterLog), asCALL_CDECL);
compileScript("test.as");
ctx = engine->CreateContext();
if(ctx == 0)
{
SLog("Failed to create the context.");
engine->Release();
return false;
}
DWORD timeOut;
if(ctx->SetLineCallback(asFUNCTION(lineCallback), &timeOut, asCALL_CDECL) < 0)
{
SLog("Failed to set the line callback function.");
ctx->Release();
engine->Release();
return false;
}
return true;
}
Load File:
bool scriptManager::compileScript(std::string scriptname)
{
FILE *f = fopen(scriptname.c_str(), "rb");
if(f == 0)
{
SLog("Failed to open the script file.");
return false;
}
fseek(f, 0, SEEK_END);
int len = ftell(f);
fseek(f, 0, SEEK_SET);
std::string script;
script.resize(len);
int c = fread(&script[0], len, 1, f);
fclose(f);
if(c == 0)
{
SLog("Failed to load script file.");
return false;
}
if(engine->AddScriptSection(0, "script", &script[0], len, 0, false) < 0)
{
SLog("AddScriptSection() failed");
return false;
}
if(engine->Build(0) < 0)
{
SLog("Build() failed");
return false;
}
return true;
}
Test.as
int helloworld(int thein)
{
return thein;
}
It crashes on if(engine->AddScriptSection(0, "script", &script[0], len, 0, false) < 0)