I wrote a small test based on your information and it works without crashing.
class CEngine{public: CEngine() {} ~CEngine() {} void BuildButton(std::string& caption, int x, int y, int width, int height, std::string& function) { assert( caption == "Test" ); assert( x == 0 ); assert( y == 0 ); assert( width == 100 ); assert( height == 100 ); assert( function == "test" ); }};static void Constructor(void *memory){ new(memory) CEngine();}static void Destructor(CEngine *p){ p->~CEngine();}bool Test2(){ int r; bool fail = false; asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); RegisterScriptString(engine); r = engine->RegisterObjectType("CEngine", sizeof(CEngine), asOBJ_VALUE | asOBJ_APP_CLASS_CDA); assert( r >= 0 ); r = engine->RegisterObjectBehaviour("CEngine", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(Constructor), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectBehaviour("CEngine", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJLAST); assert(r >= 0); r = engine->RegisterObjectMethod("CEngine", "void BuildButton(string &in, int, int, int, int, string &in)", asMETHOD(CEngine, BuildButton), asCALL_THISCALL); assert( r >= 0 ); r = engine->ExecuteString(0, "CEngine blah; blah.BuildButton('Test', 0, 0, 100, 100, 'test');"); if( r != asEXECUTION_FINISHED ) { fail = true; } engine->Release(); return fail;}
Are you sure the problem is with this method, and not something else?