The order of OnDestroy is not guaranteed, because the order of script excution doesn't work when calling OnDestroy.
class OneObj : MonoBehavior {
void OnDestroy() { NativeApi.test(); }
}
The code above will raise IndexOutofBoundException randomly when stopping game in editor.
I dont know how to solve this problem.
I am using a stupid solution:
- invoke DllManipulatorScript.Reinitialize in Awake(){} when game started.
- manually invoke DllManipulatorScript.Reset via menu item before building cpp dll.
Is there better way?