Hi all,
I am observing a strange issue while writing a script on Mac. I have a script attached to a game object, inside I have a standard queue. I push Transforms into the queue from another gameobject, but when I dequeue them the queue acts as LIFO and not FIFO.
(Thank you everyone for your responses and great ideas.)
Update: I was asked to create a test case to trigger this issue. I discovered that it only seems to trigger if the Queue is of Transform type. Here is a test case:
` using UnityEngine; using System.Collections; using System.Collections.Generic; public class TestCase : MonoBehaviour { public float delay = 0.3f; private int counter = 0; private Transform dqTransform; public Transform test; public Queue stateQueue = new Queue(); private float startTime; // Use this for initialization void Start () { startTime = Time.time + delay; } // Update is called once per frame void Update () { test = gameObject.transform; Vector3 pos = new Vector3(counter, counter, counter); test.position = pos; lock(stateQueue) { Debug.Log ("NQ:"+ test.position); stateQueue.Enqueue(test); } counter++; if (Time.time < startTime) return; PushToOthers(); } void PushToOthers() { lock(stateQueue) { if(stateQueue.Count > 0) { dqTransform = stateQueue.Dequeue(); Debug.Log ("DQ>"+dqTransform.position); } } } } `
Has anybody observed this sort of behaviour before? Any idea what is going on here? I tried with lock and without. Is this a bug? I think I can work around it using different types.