I am getting an access violation when executing a script routine from my program. I've had it working before, added some unrelated code elsewhere in the application, and this is no longer working. I am not altering anything on the heap with the new code.
as_callfunc_x64_msvc.asm
; Call function
call r14 ;CRASH HAPPENS HERE
; Restore the stack
add rsp, rdi
; EPILOG: Restore stack & preserved registers
pop rbx
pop r15
pop r14
pop r13
pop r12
pop rdi
pop r11
pop rsi
; return value in RAX
ret
This is the bytecode for the function I am calling:
void onStart(bool, bool)
Temps: 2
Variables:
000: bool isClient
-001: bool isServer
001: bool {noname param}
002: string {noname}
0 0 * PUSH 2
- 6,2 -
1 2 * SUSPEND
2 2 * CpyVtoR4 v0
3 2 * ClrHi
4 2 * JZ +12 (d:18)
- 7,3 -
6 2 * SUSPEND
7 2 * STR 0 (l:18 s:"This is a ")
8 5 * CALLSYS 31 (string _string_factory_(const int, const uint8&))
10 2 * STOREOBJ v2
11 2 * VAR v2
12 4 * GETOBJREF 0
13 4 * CALLSYS 60 (void print(const string&in))
15 2 * FREE v2, 0x1d52250 (i:30745168, f:1.51901e-316)
- 8,2 -
18 2 * 1:
18 2 * SUSPEND
19 2 * CpyVtoR4 v-1
20 2 * ClrHi
21 2 * JZ +12 (d:35)
- 9,3 -
23 2 * SUSPEND
24 2 * STR 1 (l:18 s:"This is a ")
25 5 * CALLSYS 31 (string _string_factory_(const int, const uint8&))
27 2 * STOREOBJ v2
28 2 * VAR v2
29 4 * GETOBJREF 0
30 4 * CALLSYS 60 (void print(const string&in))
32 2 * FREE v2, 0x1d52250 (i:30745168, f:1.51901e-316)
- 10,2 -
35 2 * 2:
35 2 * SUSPEND
36 2 * 0:
36 2 * RET 2
This is the C++ function:
static void __cdecl ScriptEngine::scriptPrint (const std::string &str)
{
printf(%s, str.c_str());
}
mEngine->RegisterGlobalFunction(
"void print(const string &in)",
asFUNCTION(ScriptEngine::scriptPrint),
asCALL_CDECL
);
My code is slightly more complex, but this is what I am executing:
asIScriptContext *ctx = ScriptEngine::getSingleton()->getEngine()->CreateContext();
ctx->Prepare(mRoutineID);
ctx->SetArgByte(i, (asBYTE)somevar1);
ctx->SetArgByte(i, (asBYTE)somevar2);
ctx->Execute(); //DIES HERE
ctx->Release();
Now, if I remove the print statements from the script, it works as it is no longer trying to call C++ code. Any thoughts?
When I trace, it appears to be Access Violating when calling _string_factory_.