jacksondunstan / UnityNativeScripting

Unity Scripting in C++

Home Page:https://jacksondunstan.com/articles/3938

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating a second MyGame::BaseBallScript in the demo project triggers an assertion failure

JmgrArt opened this issue · comments

Hi !
When running the example project and scene, duplicating the "GameObject with a BallScript" GameObject in the Editor or creating a second GameObject with the same component within PluginMain triggers an assertion failure.

image

Commit: 60450d4
Unity: 2017.4.5f1 64 bit
OS: Windows 10
Compiler: MSVC 2017, 64 bit

This seems to originate from the free list management for whole objects. The following patch seems to partially fix the issue when instantiating a second component within PluginMain.

diff --git a/Unity/Assets/NativeScript/Editor/GenerateBindings.cs b/Unity/Assets/NativeScript/Editor/GenerateBindings.cs
index 013fa39..c988c19 100644
--- a/Unity/Assets/NativeScript/Editor/GenerateBindings.cs
+++ b/Unity/Assets/NativeScript/Editor/GenerateBindings.cs
@@ -10162,9 +10162,9 @@ namespace NativeScript.Editor
 			outputFirstBoot.Append("\t\t{\n");
 			outputFirstBoot.Append("\t\t\tPlugin::");
 			outputFirstBoot.Append(bindingTypeName);
-			outputFirstBoot.Append("FreeWholeList[i].Next = Plugin::");
+			outputFirstBoot.Append("FreeWholeList[i].Next = (Plugin::");
 			outputFirstBoot.Append(bindingTypeName);
-			outputFirstBoot.Append("FreeWholeList[i + 1].Next;\n");
+			outputFirstBoot.Append("FreeWholeList + i + 1);\n");
 			outputFirstBoot.Append("\t\t}\n");
 
 			outputFirstBoot.Append("\t\tPlugin::");

@JmgrArt, thanks for bringing this to my attention and providing a patch. The initialization code was indeed incorrect. I've applied your suggested fix to 1cb1135 along with support for Unity 2018.2. Best, -Jackson