Unity 3b7 ArrayList Intermittent Problem

using c#.

Only started having this problem after the b7 update.
This code sometimes crashes with a NullReferenceException at
if (taskQue.Count != 0).
No idea why. Any ideas? It only happens occasionally.

public class TaskQue: MonoBehaviour
{
    #region Fields

    private ArrayList taskQue;

    #endregion

    #region Functions

    void Start()
    {
        taskQue = new ArrayList();        
    }

    public void Awake()
    {
        DontDestroyOnLoad(transform.gameObject);        
    }
    
    void Update()
    {
        if (taskQue.Count != 0)
        {
          
        }
     }
}

This only happens at startup. It doesnt just happen half way through runtime.

Its as if the start method is never called sometimes.

If I use a standard constructor instead I don’t have a problem.

I thought using a standard constructor with a monobehaviour object was not advised though.

    public TaskQue()
    {
        serverTaskQue = new ArrayList();
    }

Why are you using ArrayLists?

I haven’t seen this with generic Lists, at all. I typically initialize mine like this:

[HideInInspector] [SerializeField] List<int> fingerIDs;

#if UNITY_EDITOR
public void Initialize () {
	fingerIDs = new List<int>();
}
#endif

…and Initialize() gets called from a menu item, but it doesn’t work with all the built-in classes, so sometimes I have to do it in Start(), like

touches = new List<Touch>();

…and as I said, no problems.

That’s a good point. Too used to Java ArrayLists and their generics support. been casting. Ill try lists.

File a bug report. If it’s a bug, it needs to get fixed.

Ideally. Personally, I don’t report the little bugs that don’t matter, because there’s too much broken in Unity that actually does matter, and I’d rather have efforts concentrated there.

Keep a running list of these types of bugs, and when Unity is perfect otherwise, then report them. :wink: