Advertisement

"Your first script" not working on OSX.

Started by May 16, 2015 09:43 PM
2 comments, last by WitchLord 9 years, 6 months ago

Hi all (but more specifically Andreas I guess!)

I haven't been able to get the AngelScript example working yet (using 2.30.0). My testlog() function runs fine but the print / printf does not. I compiled AngelScript to a static library using the Xcode project in the source. The error is EXC_BAD_ACCESS at X64_CallFunction, and is possibly similar to the one in this thread.

test.as:


void main()
{
	testlog();
	print("Hello world\n");
}

callbacks:


void print(const string& in) {
    ARK2D::getLog()->e("--print--");
    ARK2D::getLog()->e(in);
}
void testlog() {
    ARK2D::getLog()->e(" we did a thing! ");
}

init and run:


       // Create the script engine
    asIScriptEngine* engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

    // Set the message callback to receive information on errors in human readable form.
    int r = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL); assert( r >= 0 );
    // AngelScript doesn't have a built-in string type, as there is no definite standard
    // string type for C++ applications. Every developer is free to register it's own string type.
    // The SDK do however provide a standard add-on for registering a string type, so it's not
    // necessary to implement the registration yourself if you don't want to.
    RegisterStdString(engine);

    r = engine->RegisterGlobalFunction("void testlog()", asFUNCTION(testlog), asCALL_CDECL);
    assert( r >= 0 );

    // Register the function that we want the scripts to call
    r = engine->RegisterGlobalFunction("void print(const string &in)", asFUNCTION(print), asCALL_CDECL);
    assert( r >= 0 );

    CScriptBuilder builder;
    r = builder.StartNewModule(engine, "MyModule");
    assert( r >= 0 );

    string script = Resource::get("test.as")->asString()->getc();

    r = builder.AddSectionFromMemory("game", script.c_str());
    assert( r >= 0 );
        
    r = builder.BuildModule();
    assert( r >= 0 );

    // Now we run it.
    // Find the function that is to be called.
    asIScriptModule *mod = engine->GetModule("MyModule");
    asIScriptFunction *func = mod->GetFunctionByDecl("void main()");
    if( func == 0 )
    {
        // The function couldn't be found. Instruct the script writer
        // to include the expected function in the script.
        printf("The script must have the function 'void main()'. Please add it and try again.\n");
        return;
    }

    // Create our context, prepare it, and then execute
    asIScriptContext *ctx = engine->CreateContext();
    ctx->Prepare(func);
    r = ctx->Execute();
    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.
            printf("An exception '%s' occurred. Please correct the code and try again.\n", ctx->GetExceptionString());
        }
    }

some disassembly:


DefaultStateBasedGame`X64_CallFunction(unsigned long const*, int, unsigned long (*)(), unsigned long&, bool):
    0x100042a7e <+174>: movq   %r10, %rax
    0x100042a81 <+177>: movq   (%rax), %rdi
    0x100042a84 <+180>: movq   0x8(%rax), %rsi
    0x100042a88 <+184>: movq   0x10(%rax), %rdx
    0x100042a8c <+188>: movq   0x18(%rax), %rcx
    0x100042a90 <+192>: movq   0x20(%rax), %r8
    0x100042a94 <+196>: movq   0x28(%rax), %r9
    0x100042a98 <+200>: addq   $0x30, %rax
    0x100042a9c <+204>: movsd  (%rax), %xmm0
    0x100042aa0 <+208>: movsd  0x8(%rax), %xmm1
    0x100042aa5 <+213>: movsd  0x10(%rax), %xmm2
    0x100042aaa <+218>: movsd  0x18(%rax), %xmm3
    0x100042aaf <+223>: movsd  0x20(%rax), %xmm4
    0x100042ab4 <+228>: movsd  0x28(%rax), %xmm5
    0x100042ab9 <+233>: movsd  0x30(%rax), %xmm6
    0x100042abe <+238>: movsd  0x38(%rax), %xmm7
    0x100042ac3 <+243>: callq  *%r11
    0x100042ac6 <+246>: movq   %r15, %rsp
    0x100042ac9 <+249>: movl   -0x49(%rbp), %ecx
    0x100042acc <+252>: testb  %cl, %cl
    0x100042ace <+254>: je     0x100042ae9               ; <+281>
    0x100042ad4 <+260>: leaq   -0x58(%rbp), %rax
    0x100042ad8 <+264>: movq   %xmm0, (%rax)
    0x100042adc <+268>: leaq   (%r13), %rdx
    0x100042ae0 <+272>: movq   %xmm1, (%rdx)
    0x100042ae4 <+276>: jmp    0x100042af1               ; <+289> at as_callfunc_x64_gcc.cpp:156


libark2d.dylib`StringFactory(unsigned int, char const*):
    0x100412ac0 <+0>:    pushq  %rbp
    0x100412ac1 <+1>:    movq   %rsp, %rbp
    0x100412ac4 <+4>:    subq   $0x120, %rsp
    0x100412acb <+11>:   movl   %edi, -0xc(%rbp)
    0x100412ace <+14>:   movq   %rsi, -0x18(%rbp)
    0x100412ad2 <+18>:   callq  0x1005e7010               ; asGetActiveContext
    0x100412ad7 <+23>:   movq   %rax, -0x20(%rbp)
    0x100412adb <+27>:   cmpq   $0x0, -0x20(%rbp)
    0x100412ae3 <+35>:   jne    0x100412b3e               ; <+126>
    0x100412ae9 <+41>:   cmpq   $0x0, -0x20(%rbp)
    0x100412af1 <+49>:   setne  %al
    0x100412af4 <+52>:   xorb   $0x1, %al
    0x100412af6 <+54>:   andb   $0x1, %al
    0x100412af8 <+56>:   movzbl %al, %ecx
    0x100412afb <+59>:   movl   %ecx, %edx
    0x100412afd <+61>:   cmpq   $0x0, %rdx
    0x100412b04 <+68>:   je     0x100412b29               ; <+105>
    0x100412b0a <+74>:   leaq   0x277cd0(%rip), %rdi      ; "StringFactory"
    0x100412b11 <+81>:   leaq   0x2776c7(%rip), %rsi      ; "/Users/admin/Dropbox/ark2d/ARK2D/src/ARK2D/vendor/angelscript/add_on/scriptstdstring/scriptstdstring.cpp"
    0x100412b18 <+88>:   movl   $0x2f, %edx
    0x100412b1d <+93>:   leaq   0x277ccb(%rip), %rcx      ; "ctx"
    0x100412b24 <+100>:  callq  0x10068116c               ; symbol stub for: __assert_rtn
    0x100412b29 <+105>:  jmp    0x100412b2e               ; <+110>
    0x100412b2e <+110>:  leaq   0x67a283(%rip), %rax      ; emptyString
    0x100412b35 <+117>:  movq   %rax, -0x8(%rbp)
    0x100412b39 <+121>:  jmp    0x100412efa               ; <+1082>
    0x100412b3e <+126>:  movq   -0x20(%rbp), %rax
    0x100412b42 <+130>:  movq   (%rax), %rcx
    0x100412b45 <+133>:  movq   %rax, %rdi
    0x100412b48 <+136>:  callq  *0x10(%rcx)
    0x100412b4b <+139>:  movl   $0x3e9, %edx
    0x100412b50 <+144>:  movl   %edx, %esi
    0x100412b52 <+146>:  movq   %rax, -0x28(%rbp)
    0x100412b56 <+150>:  movq   -0x28(%rbp), %rax
    0x100412b5a <+154>:  movq   (%rax), %rcx
    0x100412b5d <+157>:  movq   %rax, %rdi
    0x100412b60 <+160>:  callq  *0x288(%rcx)
    0x100412b66 <+166>:  movq   %rax, -0x30(%rbp)
    0x100412b6a <+170>:  cmpq   $0x0, -0x30(%rbp)
    0x100412b72 <+178>:  jne    0x100412cd7               ; <+535>
    0x100412b78 <+184>:  callq  0x100679370               ; asAcquireExclusiveLock
    0x100412b7d <+189>:  movl   $0x3e9, %eax
    0x100412b82 <+194>:  movl   %eax, %esi
    0x100412b84 <+196>:  movq   -0x28(%rbp), %rcx
    0x100412b88 <+200>:  movq   (%rcx), %rdx
    0x100412b8b <+203>:  movq   %rcx, %rdi
    0x100412b8e <+206>:  callq  *0x288(%rdx)
    0x100412b94 <+212>:  movq   %rax, -0x30(%rbp)
    0x100412b98 <+216>:  cmpq   $0x0, -0x30(%rbp)
    0x100412ba0 <+224>:  jne    0x100412cd2               ; <+530>
    0x100412ba6 <+230>:  movl   $0x30, %eax
    0x100412bab <+235>:  movl   %eax, %edi
    0x100412bad <+237>:  movq   0x64851c(%rip), %rsi      ; (void *)0x00007fff9282b4d0: std::nothrow
    0x100412bb4 <+244>:  callq  0x100681112               ; symbol stub for: operator new(unsigned long, std::nothrow_t const&)
    0x100412bb9 <+249>:  xorl   %ecx, %ecx
    0x100412bbb <+251>:  movl   %ecx, %esi
    0x100412bbd <+253>:  movb   $0x0, -0x39(%rbp)
    0x100412bc1 <+257>:  cmpq   $0x0, %rax
    0x100412bc7 <+263>:  movq   %rax, -0xb0(%rbp)
    0x100412bce <+270>:  movq   %rsi, -0xb8(%rbp)
    0x100412bd5 <+277>:  je     0x100412c15               ; <+341>
    0x100412bdb <+283>:  movq   -0xb0(%rbp), %rax
    0x100412be2 <+290>:  movq   %rax, -0x38(%rbp)
    0x100412be6 <+294>:  movb   $0x1, -0x39(%rbp)
    0x100412bea <+298>:  movq   -0xb0(%rbp), %rdi
    0x100412bf1 <+305>:  movq   %rax, -0xc0(%rbp)
    0x100412bf8 <+312>:  callq  0x10041ae40               ; std::map<char const*, std::string, std::less<char const*>, std::allocator<std::pair<char const* const, std::string> > >::map()
    0x100412bfd <+317>:  jmp    0x100412c02               ; <+322>
    0x100412c02 <+322>:  movq   -0xc0(%rbp), %rax
    0x100412c09 <+329>:  movq   %rax, -0xb8(%rbp)
    0x100412c10 <+336>:  jmp    0x100412c15               ; <+341>
    0x100412c15 <+341>:  movq   -0xb8(%rbp), %rax
    0x100412c1c <+348>:  movq   %rax, -0x30(%rbp)
    0x100412c20 <+352>:  cmpq   $0x0, -0x30(%rbp)
    0x100412c28 <+360>:  jne    0x100412c8d               ; <+461>
    0x100412c2e <+366>:  leaq   0x277bbe(%rip), %rsi      ; "Out of memory"
    0x100412c35 <+373>:  movq   -0x20(%rbp), %rax
    0x100412c39 <+377>:  movq   (%rax), %rcx
    0x100412c3c <+380>:  movq   %rax, %rdi
    0x100412c3f <+383>:  callq  *0x100(%rcx)
    0x100412c45 <+389>:  movl   %eax, -0xc4(%rbp)
    0x100412c4b <+395>:  callq  0x1006793c0               ; asReleaseExclusiveLock
    0x100412c50 <+400>:  leaq   0x67a161(%rip), %rcx      ; emptyString
    0x100412c57 <+407>:  movq   %rcx, -0x8(%rbp)
    0x100412c5b <+411>:  jmp    0x100412efa               ; <+1082>
    0x100412c60 <+416>:  movl   %edx, %ecx
    0x100412c62 <+418>:  movq   %rax, -0x48(%rbp)
    0x100412c66 <+422>:  movl   %ecx, -0x4c(%rbp)
    0x100412c69 <+425>:  testb  $0x1, -0x39(%rbp)
    0x100412c6d <+429>:  jne    0x100412c78               ; <+440>
    0x100412c73 <+435>:  jmp    0x100412c88               ; <+456>
    0x100412c78 <+440>:  movq   0x648451(%rip), %rsi      ; (void *)0x00007fff9282b4d0: std::nothrow
    0x100412c7f <+447>:  movq   -0x38(%rbp), %rdi
    0x100412c83 <+451>:  callq  0x100681100               ; symbol stub for: operator delete(void*, std::nothrow_t const&)
    0x100412c88 <+456>:  jmp    0x100412f07               ; <+1095>
    0x100412c8d <+461>:  movl   $0x3e9, %eax
    0x100412c92 <+466>:  movl   %eax, %edx
    0x100412c94 <+468>:  movq   -0x28(%rbp), %rcx
    0x100412c98 <+472>:  movq   (%rcx), %rsi
    0x100412c9b <+475>:  movq   0x280(%rsi), %rsi
    0x100412ca2 <+482>:  movq   -0x30(%rbp), %rdi
    0x100412ca6 <+486>:  movq   %rdi, -0xd0(%rbp)
    0x100412cad <+493>:  movq   %rcx, %rdi
    0x100412cb0 <+496>:  movq   -0xd0(%rbp), %rcx
    0x100412cb7 <+503>:  movq   %rsi, -0xd8(%rbp)
    0x100412cbe <+510>:  movq   %rcx, %rsi
    0x100412cc1 <+513>:  movq   -0xd8(%rbp), %r8
    0x100412cc8 <+520>:  callq  *%r8
    0x100412ccb <+523>:  movq   %rax, -0xe0(%rbp)
    0x100412cd2 <+530>:  callq  0x1006793c0               ; asReleaseExclusiveLock
    0x100412cd7 <+535>:  callq  0x100679410               ; asAcquireSharedLock
    0x100412cdc <+540>:  leaq   -0x58(%rbp), %rdi
    0x100412ce0 <+544>:  callq  0x10041ae60               ; std::_Rb_tree_iterator<std::pair<char const* const, std::string> >::_Rb_tree_iterator()
    0x100412ce5 <+549>:  leaq   -0x18(%rbp), %rsi
    0x100412ce9 <+553>:  movq   -0x30(%rbp), %rdi
    0x100412ced <+557>:  callq  0x10041ae80               ; std::map<char const*, std::string, std::less<char const*>, std::allocator<std::pair<char const* const, std::string> > >::find(char const* const&)
    0x100412cf2 <+562>:  movq   %rax, -0x60(%rbp)
    0x100412cf6 <+566>:  movq   -0x60(%rbp), %rax
    0x100412cfa <+570>:  movq   %rax, -0x58(%rbp)
    0x100412cfe <+574>:  movq   -0x30(%rbp), %rdi
    0x100412d02 <+578>:  callq  0x10041aee0               ; std::map<char const*, std::string, std::less<char const*>, std::allocator<std::pair<char const* const, std::string> > >::end()
    0x100412d07 <+583>:  leaq   -0x58(%rbp), %rdi
    0x100412d0b <+587>:  leaq   -0x68(%rbp), %rsi
    0x100412d0f <+591>:  movq   %rax, -0x68(%rbp)
    0x100412d13 <+595>:  callq  0x10041aeb0               ; std::_Rb_tree_iterator<std::pair<char const* const, std::string> >::operator!=(std::_Rb_tree_iterator<std::pair<char const* const, std::string> > const&) const
    0x100412d18 <+600>:  testb  $0x1, %al
    0x100412d1a <+602>:  jne    0x100412d25               ; <+613>
    0x100412d20 <+608>:  jmp    0x100412d42               ; <+642>
    0x100412d25 <+613>:  callq  0x100679460               ; asReleaseSharedLock
    0x100412d2a <+618>:  leaq   -0x58(%rbp), %rdi
    0x100412d2e <+622>:  callq  0x10041af10               ; std::_Rb_tree_iterator<std::pair<char const* const, std::string> >::operator->() const
    0x100412d33 <+627>:  addq   $0x8, %rax
    0x100412d39 <+633>:  movq   %rax, -0x8(%rbp)
    0x100412d3d <+637>:  jmp    0x100412efa               ; <+1082>
    0x100412d42 <+642>:  callq  0x100679460               ; asReleaseSharedLock
    0x100412d47 <+647>:  callq  0x100679370               ; asAcquireExclusiveLock
    0x100412d4c <+652>:  leaq   -0x18(%rbp), %rsi
    0x100412d50 <+656>:  movq   -0x30(%rbp), %rdi
    0x100412d54 <+660>:  callq  0x10041ae80               ; std::map<char const*, std::string, std::less<char const*>, std::allocator<std::pair<char const* const, std::string> > >::find(char const* const&)
    0x100412d59 <+665>:  movq   %rax, -0x70(%rbp)
    0x100412d5d <+669>:  movq   -0x70(%rbp), %rax
    0x100412d61 <+673>:  movq   %rax, -0x58(%rbp)
    0x100412d65 <+677>:  movq   -0x30(%rbp), %rdi
    0x100412d69 <+681>:  callq  0x10041aee0               ; std::map<char const*, std::string, std::less<char const*>, std::allocator<std::pair<char const* const, std::string> > >::end()
    0x100412d6e <+686>:  leaq   -0x58(%rbp), %rdi
    0x100412d72 <+690>:  leaq   -0x78(%rbp), %rsi
    0x100412d76 <+694>:  movq   %rax, -0x78(%rbp)
    0x100412d7a <+698>:  callq  0x10041af30               ; std::_Rb_tree_iterator<std::pair<char const* const, std::string> >::operator==(std::_Rb_tree_iterator<std::pair<char const* const, std::string> > const&) const
    0x100412d7f <+703>:  testb  $0x1, %al
    0x100412d81 <+705>:  jne    0x100412d8c               ; <+716>
    0x100412d87 <+711>:  jmp    0x100412ee2               ; <+1058>
    0x100412d8c <+716>:  movq   -0x30(%rbp), %rdi
    0x100412d90 <+720>:  movq   -0x18(%rbp), %rsi
    0x100412d94 <+724>:  movl   -0xc(%rbp), %eax
    0x100412d97 <+727>:  movl   %eax, %edx
    0x100412d99 <+729>:  leaq   -0xa8(%rbp), %rcx
    0x100412da0 <+736>:  movq   %rdi, -0xe8(%rbp)
    0x100412da7 <+743>:  movq   %rcx, %rdi
    0x100412daa <+746>:  movq   %rcx, -0xf0(%rbp)
    0x100412db1 <+753>:  movq   %rsi, -0xf8(%rbp)
    0x100412db8 <+760>:  movq   %rdx, -0x100(%rbp)
    0x100412dbf <+767>:  callq  0x100680eba               ; symbol stub for: std::allocator<char>::()
    0x100412dc4 <+772>:  leaq   -0xa0(%rbp), %rdi
    0x100412dcb <+779>:  movq   -0xf8(%rbp), %rsi
    0x100412dd2 <+786>:  movq   -0x100(%rbp), %rdx
    0x100412dd9 <+793>:  movq   -0xf0(%rbp), %rcx
    0x100412de0 <+800>:  callq  0x100680fa4               ; symbol stub for: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, unsigned long, std::allocator<char> const&)
    0x100412de5 <+805>:  jmp    0x100412dea               ; <+810>
    0x100412dea <+810>:  leaq   -0x98(%rbp), %rdi
    0x100412df1 <+817>:  leaq   -0x18(%rbp), %rsi
    0x100412df5 <+821>:  leaq   -0xa0(%rbp), %rdx
    0x100412dfc <+828>:  callq  0x10041af90               ; std::pair<char const* const, std::string>::pair(char const* const&, std::string const&)
    0x100412e01 <+833>:  jmp    0x100412e06               ; <+838>
    0x100412e06 <+838>:  leaq   -0x98(%rbp), %rsi
    0x100412e0d <+845>:  movq   -0xe8(%rbp), %rdi
    0x100412e14 <+852>:  callq  0x10041af60               ; std::map<char const*, std::string, std::less<char const*>, std::allocator<std::pair<char const* const, std::string> > >::insert(std::pair<char const* const, std::string> const&)
    0x100412e19 <+857>:  movb   %dl, -0x101(%rbp)
    0x100412e1f <+863>:  movq   %rax, -0x110(%rbp)
    0x100412e26 <+870>:  jmp    0x100412e2b               ; <+875>
    0x100412e2b <+875>:  movq   -0x110(%rbp), %rax
    0x100412e32 <+882>:  movq   %rax, -0x88(%rbp)
    0x100412e39 <+889>:  movb   -0x101(%rbp), %cl
    0x100412e3f <+895>:  movb   %cl, -0x80(%rbp)
    0x100412e42 <+898>:  movq   -0x88(%rbp), %rdx
    0x100412e49 <+905>:  movq   %rdx, -0x58(%rbp)
    0x100412e4d <+909>:  leaq   -0x98(%rbp), %rdi
    0x100412e54 <+916>:  callq  0x10041ad60               ; std::pair<char const* const, std::string>::~pair()
    0x100412e59 <+921>:  jmp    0x100412e5e               ; <+926>
    0x100412e5e <+926>:  leaq   -0xa0(%rbp), %rdi
    0x100412e65 <+933>:  callq  0x100680fbc               ; symbol stub for: std::string::~()
    0x100412e6a <+938>:  jmp    0x100412e6f               ; <+943>
    0x100412e6f <+943>:  leaq   -0xa8(%rbp), %rdi
    0x100412e76 <+950>:  callq  0x100680ec6               ; symbol stub for: std::allocator<char>::~()
    0x100412e7b <+955>:  jmp    0x100412ee2               ; <+1058>
    0x100412e80 <+960>:  movl   %edx, %ecx
    0x100412e82 <+962>:  movq   %rax, -0x48(%rbp)
    0x100412e86 <+966>:  movl   %ecx, -0x4c(%rbp)
    0x100412e89 <+969>:  jmp    0x100412ed1               ; <+1041>
    0x100412e8e <+974>:  movl   %edx, %ecx
    0x100412e90 <+976>:  movq   %rax, -0x48(%rbp)
    0x100412e94 <+980>:  movl   %ecx, -0x4c(%rbp)
    0x100412e97 <+983>:  jmp    0x100412ebb               ; <+1019>
    0x100412e9c <+988>:  movl   %edx, %ecx
    0x100412e9e <+990>:  movq   %rax, -0x48(%rbp)
    0x100412ea2 <+994>:  movl   %ecx, -0x4c(%rbp)
    0x100412ea5 <+997>:  leaq   -0x98(%rbp), %rdi
    0x100412eac <+1004>: callq  0x10041ad60               ; std::pair<char const* const, std::string>::~pair()
    0x100412eb1 <+1009>: jmp    0x100412eb6               ; <+1014>
    0x100412eb6 <+1014>: jmp    0x100412ebb               ; <+1019>
    0x100412ebb <+1019>: leaq   -0xa0(%rbp), %rdi
    0x100412ec2 <+1026>: callq  0x100680fbc               ; symbol stub for: std::string::~()
    0x100412ec7 <+1031>: jmp    0x100412ecc               ; <+1036>
    0x100412ecc <+1036>: jmp    0x100412ed1               ; <+1041>
    0x100412ed1 <+1041>: leaq   -0xa8(%rbp), %rdi
    0x100412ed8 <+1048>: callq  0x100680ec6               ; symbol stub for: std::allocator<char>::~()
    0x100412edd <+1053>: jmp    0x100412f07               ; <+1095>
    0x100412ee2 <+1058>: callq  0x1006793c0               ; asReleaseExclusiveLock
    0x100412ee7 <+1063>: leaq   -0x58(%rbp), %rdi
    0x100412eeb <+1067>: callq  0x10041af10               ; std::_Rb_tree_iterator<std::pair<char const* const, std::string> >::operator->() const
    0x100412ef0 <+1072>: addq   $0x8, %rax
    0x100412ef6 <+1078>: movq   %rax, -0x8(%rbp)
    0x100412efa <+1082>: movq   -0x8(%rbp), %rax
    0x100412efe <+1086>: addq   $0x120, %rsp
    0x100412f05 <+1093>: popq   %rbp
    0x100412f06 <+1094>: retq   
    0x100412f07 <+1095>: movq   -0x48(%rbp), %rdi
    0x100412f0b <+1099>: callq  0x100681166               ; symbol stub for: _Unwind_Resume
    0x100412f10 <+1104>: movl   %edx, %ecx
    0x100412f12 <+1106>: movq   %rax, %rdi
    0x100412f15 <+1109>: movl   %ecx, -0x114(%rbp)
    0x100412f1b <+1115>: callq  0x1002807b0               ; __clang_call_terminate


libark2d.dylib`asGetActiveContext:
    0x1005e7010 <+0>:   pushq  %rbp
    0x1005e7011 <+1>:   movq   %rsp, %rbp
    0x1005e7014 <+4>:   subq   $0x20, %rsp
    0x1005e7018 <+8>:   callq  0x100679820               ; asCThreadManager::GetLocalData()
    0x1005e701d <+13>:  movq   %rax, -0x10(%rbp)
    0x1005e7021 <+17>:  movq   -0x10(%rbp), %rdi
    0x1005e7025 <+21>:  callq  0x1006809fe               ; symbol stub for: asCArray<asIScriptContext*>::GetLength() const
    0x1005e702a <+26>:  cmpl   $0x0, %eax
    0x1005e702f <+31>:  jne    0x1005e7042               ; <+50>
    0x1005e7035 <+37>:  movq   $0x0, -0x8(%rbp)
    0x1005e703d <+45>:  jmp    0x1005e706d               ; <+93>
    0x1005e7042 <+50>:  movq   -0x10(%rbp), %rdi
    0x1005e7046 <+54>:  movq   -0x10(%rbp), %rax
    0x1005e704a <+58>:  movq   %rdi, -0x18(%rbp)
    0x1005e704e <+62>:  movq   %rax, %rdi
    0x1005e7051 <+65>:  callq  0x1006809fe               ; symbol stub for: asCArray<asIScriptContext*>::GetLength() const
    0x1005e7056 <+70>:  subl   $0x1, %eax
    0x1005e705b <+75>:  movq   -0x18(%rbp), %rdi
    0x1005e705f <+79>:  movl   %eax, %esi
    0x1005e7061 <+81>:  callq  0x10067f966               ; symbol stub for: asCArray<asIScriptContext*>::operator[](unsigned int)
    0x1005e7066 <+86>:  movq   (%rax), %rax
    0x1005e7069 <+89>:  movq   %rax, -0x8(%rbp)
    0x1005e706d <+93>:  movq   -0x8(%rbp), %rax
    0x1005e7071 <+97>:  addq   $0x20, %rsp
    0x1005e7075 <+101>: popq   %rbp
    0x1005e7076 <+102>: retq   
    0x1005e7077 <+103>: nopw   (%rax,%rax)


libark2d.dylib`asCArray<asIScriptContext*>::GetLength:
    0x100679b30 <+0>:  pushq  %rbp
    0x100679b31 <+1>:  movq   %rsp, %rbp
    0x100679b34 <+4>:  movq   %rdi, -0x8(%rbp)
    0x100679b38 <+8>:  movq   -0x8(%rbp), %rdi
->  0x100679b3c <+12>: movl   0x8(%rdi), %eax
    0x100679b3f <+15>: popq   %rbp
    0x100679b40 <+16>: retq   
    0x100679b41 <+17>: nopw   %cs:(%rax,%rax)

Program state:

[attachment=27314:Screen Shot 2015-05-16 at 22.33.05.png]

Call stack:

[attachment=27315:Screen Shot 2015-05-16 at 22.42.12.png]

This is on OSX 10.10, Xcode 6.3.1 and compiling with default compiler Apple LLVM 6.1, no optimisations (-O0). If I need to give you any more information, I'll be happy to supply you with it. Cheers!

Hi Gwinnel,

Apparently the problem happens in the StringFactory, or more specifically in asGetActiveContext called by StringFactory.

I believe this problem may actually be unrelated to the native calling conventions, and instead a problem with the multi-thread support.

Unfortunately I do not have a 64bit Mac to test the code with, so I'll have to rely on you to find the cause of the problem.

- Can you verify the return of the function asGetLibraryOptions()? It will help me confirm how the library was compiled.

- Can you also do debug session to check what goes on in asGetActiveContext()? I suspect the method asCThreadManager::GetLocalData() that it calls is for some reason returning a null-pointer and this is why it crashes. If my suspicion is correct can you try to understand why the return is a null-pointer?

Regards,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

asGetLibraryOptions() returns

AS_64BIT_PTR AS_MAC AS_X64_GCC

I've managed to the fix the error, but in a way that suggests there's nothing wrong with the AngelScript library... My project structure is game [ framework [ angelscript ] ], and I just noticed I was statically linking AS to both the framework and the game. I can still investigate further if you think there's a genuine bug, but otherwise it's all magically fixed. :)

Cheers!

Linking with AngelScript from both the framework and the game may have ended up giving two different instances of the asGetActiveContext in the game. I'm not sure why the linker didn't complain about the duplicate instances, or else automatically eliminate one of them, but it would explain how asGetActiveContext() could receive a null pointer from asCThreadManager::GetLocalData().

Anyway, I'll have to make an improvement in asGetActiveContext to check for a null-pointer before trying to access the member of the thread local memory.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement