On 04/06/2014 at 23:35, xxxxxxxx wrote:
User Information:
Cinema 4D Version: R15
Platform: Windows ; Mac OSX ;
Language(s) : C++ ;
---------
As part of our FUSEE 3D OpenSource game engine project we developed a CINEMA 4D plugin exporting the currently visible geometry and part of the material settings to an interactive HTML 5/WebGL application (see http://fusee3d.org/c4dexporter/). On Windows everything works pretty well (download the free plugin and try it if you like to).
While porting the plugin to MAC OS, I encountered some strange behavior. The plugin works well on MAC, only when closing CINEMA 4D, the application hangs and needs to be killed manually. Debugging shows that our plugin receives the C4DPL_END message and properly passes PluginEnd, FreeHelpDelegates, FreeResources and DeleteObj. The crash occurs afterwards somewhere inside CINEMA4D code. I attached the disassembly below. The following exception occurs at the mov instruction in the red/bold/underlined code line: "Thread 1: EXC_BAD_ACCESS (code=1, address=0x113d6a210).
Since I am pretty new to MAC development in general and especially C4D plugin development on MAC I would be happy for any suggestion how to further track down that problem.
Christoph
tl;tr:
Some background information: The functionality of our PlugIn is developed in .NET/C#. To be able to run it within C4D we wrapped huge parts of the C4D-C++-API to C# (currently 700 types (classes/enums/structs) with more than 1000 methods). We do this automatically using the SWIG wrapper generator. To actually run the plugIn we developed a generic C4D-C++ plugin that starts up the .NET runtime OR the Mono runtime on Windows (user may choose) which both works pretty well. On MAC only the mono runtime is available, since .NET is Microsoft-Land. As already said, everything works fine on MAC as well - even a hand-coded C# local web-server running inside the plugin worked on MAC right from the start as compiled on Windows(!), only with the resulting crash on shutdown. I completely stripped out our C#-functionality and observed that the crash happens if only the mono runtime is started during our C++part of the plugin without performing any of our C# custom code. So the question is: what could the mono runtime do that makes C4D crash once the mono runtime is shutdown without any problems? Are there any debug symbols available to identify all the __lldb_unamed_function$$CINEMA 4D listed in the disassembly below? Thanks!
CINEMA 4D`___lldb_unnamed_function1$$CINEMA 4D:
0x100001970: pushq $0x0
0x100001972: movq %rsp, %rbp
0x100001975: andq $-0x10, %rsp
0x100001979: movq 0x8(%rbp), %rdi
0x10000197d: leaq 0x10(%rbp), %rsi
0x100001981: movl %edi, %edx
0x100001983: addl $0x1, %edx
0x100001986: shll $0x3, %edx
0x100001989: addq %rsi, %rdx
0x10000198c: movq %rdx, %rcx
0x10000198f: jmp 0x100001995 ; ___lldb_unnamed_function1$$CINEMA 4D + 37
0x100001991: addq $0x8, %rcx
0x100001995: cmpq $0x0, (%rcx)
0x100001999: jne 0x100001991 ; ___lldb_unnamed_function1$$CINEMA 4D + 33
0x10000199b: addq $0x8, %rcx
0x10000199f: callq 0x100a5aad0 ; ___lldb_unnamed_function22807$$CINEMA 4D
0x1000019a4: movl %eax, %edi
0x1000019a6: callq 0x100cb3352 ; symbol stub for: exit
0x1000019ab: hlt
0x1000019ac: nop
0x1000019ad: nop
0x1000019ae: nop
0x1000019af: nop