Hey all. I am having a bit of an issue. The application compiles fine on both Windows 64bit and Linux 64bit (using the most recent available version from the The ArchLinux AUR [2.18.2-1 as of this writing]), but it seems that only on the linux version this problem arises. I even gave the source to a friend and he was able to compile and run on windows jut fine.
Here is the test code I am using:
/*
Short test of angelscript functionality.
*/
#include <iostream>
#include <cassert>
#include "TestClass.h"
#include "scriptbuilder.h"
#include "scriptstring.h"
#include <angelscript.h>
int main(void)
{
int r;
asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);
RegisterScriptString(engine);
RegisterScriptStringUtils(engine);
std::cout<<"r = engine->RegisterObjectType(TestClass,sizeof(TestClass),asOBJ_REF); assert(r>=0);\n";
r = engine->RegisterObjectType("TestClass",sizeof(TestClass),asOBJ_REF); assert(r>=0);
std::cout<<"r = engine->RegisterObjectBehaviour(TestClass,asBEHAVE_FACTORY,TestClass@ f(), asFUNCTION(ClassFactory), asCALL_CDECL);\n";
r = engine->RegisterObjectBehaviour("TestClass", asBEHAVE_FACTORY,
"TestClass@ f()", asFUNCTION(ClassFactory), asCALL_CDECL);
assert( r >= 0 );
std::cout<<"r = engine->RegisterObjectBehaviour(TestClass,asBEHAVE_ADDREF,void f(),asMETHOD(TestClass,AddRef), asCALL_THISCALL);\n";
r = engine->RegisterObjectBehaviour("TestClass",asBEHAVE_ADDREF,"void f()",asMETHOD(TestClass,AddRef), asCALL_THISCALL);
assert(r>=0);
std::cout<<"r = engine->RegisterObjectBehaviour(TestClass,asBEHAVE_RELEASE,void f(),asMETHOD(TestClass,Release), asCALL_THISCALL);\n";
r = engine->RegisterObjectBehaviour("TestClass",asBEHAVE_RELEASE,
"void f()",asMETHOD(TestClass,Release), asCALL_THISCALL);
assert(r>=0);
std::cout<<"r=engine->RegisterObjectMethod(TestClass,void print(string@),asMETHOD(TestClass,TC_Print),asCALL_THISCALL);\n";
r=engine->RegisterObjectMethod("TestClass", "void print(string@)",asMETHOD(TestClass,TC_Print),asCALL_THISCALL);
assert(r>=0);
std::cout<<"r = engine->RegisterObjectMethod(TestClass,void count(int),asMETHOD(TestClass,TC_Count), asCALL_THISCALL);\n";
r = engine->RegisterObjectMethod("TestClass", "void count(int)",asMETHOD(TestClass,TC_Count), asCALL_THISCALL);
assert(r>=0);
std::cout<<"CScriptBuilder builder;\n";
CScriptBuilder builder;
std::cout<<"r = builder.StartNewModule(engine,Base);\n";
r = builder.StartNewModule(engine, "Base");
if( r < 0 ) { std::cout<<"Out of memory."; return 0; } r = builder.AddSectionFromFile("./main.script");
if( r < 0 ) { std::cout<<"Please correct the errors in the script and try again.\n"; return 0; }
std::cout<<"r = builder.BuildModule();";
r = builder.BuildModule();
if( r < 0 ) { std::cout<<"Failed to build module.\n"; return 0; }
std::cout<<"asIScriptModule *mod = engine->GetModule(Base);\n";
asIScriptModule *mod = engine->GetModule("Base");
std::cout<<"int funcId = mod->GetFunctionIdByDecl(void run());\n";
int funcId = mod->GetFunctionIdByDecl("void run()"); // gets right up to here.
// and I know the segfault occurs here because the following block never gets run
// with the if contidtion commented out, asIScriptContext *ctx = engine->CreateContext(); never runs either
std::cout<<"if( funcId < 0 )";
/* if( funcId < 0 )
{
// The function couldn't be found. Instruct the script writer
// to include the expected function in the script.
std::cout<<"The script must have the function 'void run()'. Please add it and try again.\n";
return 0;
}*/
std::cout<<"asIScriptContext *ctx = engine->CreateContext();";
// Create our context, prepare it, and then execute
asIScriptContext *ctx = engine->CreateContext();
std::cout<<"ctx->Prepare(funcId);";
ctx->Prepare(funcId);
std::cout<<"r = ctx->Execute();";
r = ctx->Execute();
std::cout<<"if( r != asEXECUTION_FINISHED )";
if( r != asEXECUTION_FINISHED )
{
// The execution didn't complete as expected. Determine what happened.
if( r == asEXECUTION_EXCEPTION )
{
// An exception occurred, let the script writer know what happened so it can be corrected.
std::cout<<"An exception \'"
<<ctx->GetExceptionString()<<
"\' occurred. Please correct the code and try again.\n";
}
}
}
Here is the GDB backtrace
Building to ensure sources are up-to-date
Build succeeded
Selecting target:
Debug
Adding source dir: /media/sdd1/AngelScriptTest/
Adding source dir: /media/sdd1/AngelScriptTest/
Adding file: bin/Debug/AngelScriptTest
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.1
Program received signal SIGSEGV, Segmentation fault.
In X64_CallFunction(unsigned int const*, unsigned char const*, void*) () (/usr/lib/libangelscript-2.18.2.so)
Debugger finished with status 0
Anyone have any insight? AngelScript is a great language to work with and it is a shame that this is happening.