- Home /
Queue> not working?
Hi !
Using : C#
I ran onto a strange bug this week... in my code, I'm using a Queue<KeyValuePair<string,int>> to store a type of ennemy(string) and how many I need to spawn(int).
If I'm trying to something like :
list<string> aList = new list<string>();
aList[0] = aQueue.Dequeue().Key;
This code works in the editor, but not in the build.(Building for PC) In fact, the line where I dequeue and everything after is not executed in the build. The wierd thing is that everything before this line is executed...
I placed a GUIText that changes his text to debug this in the build....so I know that it is this exact line.
No errors, no warnings in the console.
Very weird.
Is there any complex data structure that Unity can't handle ?
Thank you
Answer by Ianson · Feb 10, 2014 at 02:35 PM
I know this is a very old thread but I had this problem too.
if you go into monodevelop and go to Run >> Exceptions you can add exception types to the list of exceptions. this will catch the exception in the editor and make it easier to debug...
But, in a nut shell you need to check the queue count before accessing it. Even .Peek() will throw an exception if your queue is empty- which makes very little sense in my opinion. If it returned null at least you would get a null exception when you tried to dequeue which is far more useful...
Answer by tertle · Feb 23, 2011 at 03:33 AM
I don't really understand why it'd work in the editor, but not when you actually build it.
Out of interest, what type of List are you using? Is it the standard System.Collections.Generic.List?
Have you tried
List<string> aList = new List<string>();
aList.Add(aQueue.Dequeue().Key);
Good point -- even trying to set element 0 should throw an ArgumentOutOfRange exception if the list is empty. Add is the way to go.
Answer by Michael 17 · Feb 23, 2011 at 04:45 PM
I tried changing the data structure and the same thing is happening.
This line is not working in the build but do works in the editor :
string strEnnemyType = EnnemyType.Dequeue();
I'm running out of ideas... this is really annoying. I'm tried the script on a new project, and it's doing the same thing.
I'm using the System.Collections.Generic
Next step: I'm gonna try it on another computer...
Answer by Blr. · Sep 28, 2012 at 08:54 PM
I have the same problem too, inside the editor everything works fine but inside Xcode I got the this message:
InvalidOperationException: Operation is not valid due to the current state of the object at System.Collections.Generic.Queue`1[System.Single].Peek () [0x0000b] in /Applications/buildAgent/work/51c26656ff47b7e8/mcs/class/System/System.Collections.Generic/Queue.cs:154 at System.Collections.Generic.Queue`1[System.Single].Dequeue () [0x00000] in /Applications/buildAgent/work/51c26656ff47b7e8/mcs/class/System/System.Collections.Generic/Queue.cs:138
(Filename: /Applications/buildAgent/work/51c26656ff47b7e8/mcs/class/System/System.Collections.Generic/Queue.cs Line: 154)
private Queue<float> m_que = new Queue<float>();
void Awake(){
for(int i=0; i<m_sample; ++i){
m_que.Enqueue(0);
}
}
void Update (){
m_que.Dequeue();
m_que.Enqueue(vAcc.x);
}
Your answer