Arbitrary line in one method prevents another for working?
This is blowing my mind....
I have a loop.
IEnumerator Start()
{
while(true) {
if(collectedFloatList.Count > 0){
OverallLatencyReport(collectedFloatList.Avarage); // < Call Method 1;
CheckForEvent (collectedFloatList); // Call Method 2;
}
yield return new WaitForSeconds(1f);
}
}
The problem is, this works perfectly fine if I comment out Method 2, "CheckForEvent" but with the method in there, it will not execute method 1 "OverallLatencyReport". So I started commenting out some lines, in Method 2 and found the line that makes method 1 stop working but that line has nothing to do with Method 1. What is worse is that if I swap the "guilty" line with another line that also has nothing to do with Method 1, and comment out the guilty line, the new random line becomes the "guilty" line and stops method one for working.
I do not understand what I am missing.
Here is Method 1 and 2.
void OverallLatencyReport(float lag) // This method does not do the job when "guilty" line is active
{
GameObject lagBarClone = Instantiate (latencyHitPrefab) as GameObject;
lagBarClone.transform.SetParent(graphParent);
activeGraphHits.Enqueue(lagBarClone);
lagBarClone.GetComponent<Slider>().value = lag;
if(activeGraphHits.Count > maxGraphHit)
Destroy(activeGraphHits.Dequeue());
overallLatencyInfo.text = (lag).ToString() + " ms";
}
And this is the method with the "guilty" line?
void CheckForEvent(List<float> ALPS)
{
float minLatency = ALPS.Min();
float.maxLatency = ALPS.Max();
bool spike = (minLatency *2 < maxLatency);
bool drop = (maxLatency / 2 > minLatency);
if(spike){
GameObject textClone = Instantiate (eventTextPrefab) as GameObject) as GameObject;
Text newEvent = textClone.GetComponent<Text>();
newEvent.transform.SetParent(eventParent); // This is the guilty line if not commented out
// BUT!!! if I comment it out, and I uncomment the next line like so.
// newEvent.transform.SetParent(eventParent);
newEvent.text = "Spike at " + (Time.time -autoToggleTime).ToString(); // Now this is the guilty line and stops the first method for performing.
}
}
No error, just stops working. Any ideas?
Don't tag people who have nothing to do with this question, and it hasn't "been a while", it's less than a day.
Answer by phil_me_up · Mar 04, 2016 at 01:25 AM
Are you getting any errors in the console?
My guess is that as both "guilty" lines are using 'newEvent', the problem is that newEvent is null, which causes an exception and halt the coroutine (assuming Start is a coroutine. If so you might want to rename for clarity).
If the above is correct, you need to look at how newEvent is set and that your GetConponent call is successful (will fail if the Text component can't be found).
I wish it was this simple, I can replace the "guilty" line with "Debug.Log("write something"); and it will break the system. It appears not to be the content of the line but the count? There is no error and the item is not null. It appears to be deeper than that.