weird memory (heap) corruption bug when using inspector when game running (uinity 3.1

It’s taken me a full day to track this bug down so I thought I’d post about it. it’s quite a bad one. What hapened was that my game suddenly started crashing when I changed any value in the inspector. Worked fine up till yesterday then suddenly it went bad. After much head scratching I eventually found out it was because I’d made an array of objects public (so I could access them from another class). Basically I create a list of rooms when the game starts up in the list rooms. If I make that list public then it shows up as a list of null variables. If I change ANY variable in the inspector the list becomes corrupt and the game frequently crashes. Making the list NonSerializable solves the problem. Why would this be?

public class Room:UnityEngine.Object
{
}

//causes problems
public List rooms = new List();

//works fine
[System.NonSerialized]
public List rooms = new List();

As an aside why does any object which is derived from UnityEngine.Object return false when compared to null? E.g. the following always returns true:

Room room = null;
if(room != null)
Debug.Log(“Always runs this line”)

this on the other hand works as expected:

Room room = null;
if((object)room != null)
Debug.Log(“Never runs this line”)

I’m guessing it’s because the unityengine.object overloads teh equivalence operator but what for?

regards,

tony

Your code which crashes Unity seems to work OK on my machine. Please can you file a bug report for it (menu: Help > Report A Bug) and attach the project if possible.

Also, I don’t get the behaviour with the null pointer - the code works OK for me. Can you post the whole source file?

Thanks Andy,

I don’t really want to send the source because it contains code we don’t want to share yet. What I’ll do is create a new project and see if I can reproduce the problem. If I can’t then I guess that means I have to dig a bit deeper and work out what’s gone wrong with the other project.

thanks for taking the time to reply to my thread.