I have an asset on the asset store that dynamically loads terrain or other game objects. Everything worked great on 4.2, however, after updating to 4.3, the Unity Editor and Windows Standalone Builds crash when a Terrain is destroyed.
If I use a regular GameObject with no Terrain Component (such as a plane), my dynamic loading program has no trouble destroying the objects, so I know it’s something to do with Terrains.
Here is the relevant code where the crash occurs. Note, this code is in a component and is called by another component, and both components are found in a .dll:
public sealed override void ProcessDeactivatedCellObjects(List<GameObject> deactivatedCellObjects,
List<ICellLoadData> cellsAssociatedWithObjects)
{
for(int i = 0; i < cellsAssociatedWithObjects.Count; i++)
{
Debug.Log("Destroy object " + i);
Destroy(deactivatedCellObjects[i]);
Debug.Log("Object " + i + " destroyed");
//yield return new WaitForSeconds(timeToYieldForAfterDestroyingCellObject);
}
//yield break;
}
The commented yields are there because initially this was a Coroutine, and when I was trying to figure out where the crash was occurring using the Debug.Log calls, the method would print “Object 1 destroyed” then crash, so I suspected the yield was causing an issue. However, after removing the yields and making it a method with return type void (changing how the method was called as well), the program still crashes. The differences is the Debug.Log statements print for every object that is destroyed, making me believe the issue is not with the Destroy method, however the program still crashes.
Also, if I switch out the component with the Destroy method for one that doesn’t Destroy the object, there is no crashing, which supports the theory that there is an issue with trying to Destroy terrains.
Confusing matters however, is the fact that I have tried to reproduce this crash and cannot seem to do so. I created code that effectively does the same as the code posted (destroying Terrains), and even put the code in a .dll, but no crashing occurs.
I’ve submitted a bug report, but I really want to try and fix this myself (if possible) as soon as possible, because I said this is an Asset Store product and crashing is a huge issue.
Thanks for any help!