- Home /
Code requirements for C++ plugin in Unity
I have some working C++ code that I would like to pull into Unity3d.
I am able to compile a bundle in Xcode and have it show up in Unity3d. Dummy functions within the plugin (e.g. a function I wrote called "ReturnFour", a basic function that returns 4) work fine. However, when I try to execute more complex functions, I get memory leaks:
Here's the output from the crash report:
Crashed Thread: 0 CrBrowserMain Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
abort() called
*** error for object 0x12ba79b20: pointer being freed was not allocated
Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff84a2f002 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fff807ac5c5 pthread_kill + 90
2 libsystem_c.dylib 0x00007fff8bdca6e7 abort + 129
3 libmono.0.dylib 0x0000000109ca4e0e mono_handle_native_sigsegv + 732
4 libmono.0.dylib 0x0000000109cec8ff 0x109c32000 + 764159
5 libsystem_platform.dylib 0x00007fff80c88eaa _sigtramp + 26
6 ??? 0x000000012573ae41 0 + 4923305537
7 libsystem_c.dylib 0x00007fff8bdca6e7 abort + 129
8 libsystem_malloc.dylib 0x00007fff89ffd070 free + 425
9 libstdc++.6.dylib 0x00007fff82c23d1c std::string::_M_mutate(unsigned long, unsigned long, unsigned long) + 332
10 libstdc++.6.dylib 0x00007fff82c247be std::string::assign(char const*, unsigned long) + 78
11 com.yourcompany.ASimplePlugin 0x000000012594357c BioFVM::Microenvironment::Microenvironment() + 936 (BioFVM_microenvironment.cpp:91)
12 com.yourcompany.ASimplePlugin 0x000000012592f0a7 PrintFour + 37 (trial.cpp:30)
I guess it's possible that my code has memory leaks, but It's been extensively tested in the past and I don't think it does.
Is there some basic memory requirement/compilation tag that I need to respect to produce a bundle that plays well with U3D?
According to that error message you're using a pointer that hasn't been instantiated yet. Are you sure you don't have one floating around from when you implemented the merge to Unity?
Your answer
Follow this Question
Related Questions
Performance: C# vs C++ (plugin) 0 Answers
Making a plugin from an open source music language 0 Answers
Unity plugins 0 Answers
Detecting a word clicked on in 3D text? 1 Answer
Is there a way to create a C++ Managed DLL for Unity? 0 Answers