- Home /
Unity freeze with RegExp
I can freeze Unity 100% with the following code.
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
public class Test : MonoBehaviour
{
void Start()
{
Regex reSym = new Regex(@"^\s*(\-?\b*[_a-zA-Z]+[_a-zA-Z0-9]*)");
Match m = reSym.Match("0.1+0.2");
}
}
Any ideas how to work around this.. bug?
Comment
The problem seems to have been with \b*
Though, I'm not sure WHY this was a problem.
Answer by Graham-Dunnett · Oct 24, 2011 at 01:31 PM
The editor and your game script share the same mono. I do not know if your RegEx is correct or not, but I wonder if you've got the Regex code into a loop somehow. Infinite loops or recursive code with no exit conditions can cause Unity to appear unresponsive as the game script consumes all the cpu. Probably not a bug in Unity.
Is it possible to put RegExp code into an infinite loop?
Also, this code works fine when compiled in stand-alone C# (IE NOT mono).