1
Other Packages / Fog of War Thread Error
« on: February 26, 2015, 08:51:59 AM »
So using the FoW system, I ran into an issue where instantiating new prefabs with revealers on them would sometimes cause the entire FoW system to break and stop responding.
I managed to trace the issue down to a buffer not having the proper data at the time of updating which caused an error which silently killed the thread.
In the FOWSystem.cs file I made the following changes which seem to have made it resilient to this problem. The try/catch allows the thread to keep working when the instantiating buffer problem happens, and it seems to have kept things alive for me? Posting it here in case anyone else has this issue!
Note, the "Thread is alive" check in the late update function is a last-ditch effort to restart the system if it dies for another reason. It wasn't ever fired once the try/catch was put in the ThreadUpdate method.
I managed to trace the issue down to a buffer not having the proper data at the time of updating which caused an error which silently killed the thread.
In the FOWSystem.cs file I made the following changes which seem to have made it resilient to this problem. The try/catch allows the thread to keep working when the instantiating buffer problem happens, and it seems to have kept things alive for me? Posting it here in case anyone else has this issue!
Note, the "Thread is alive" check in the late update function is a last-ditch effort to restart the system if it dies for another reason. It wasn't ever fired once the try/catch was put in the ThreadUpdate method.
- @@ -284,6 +284,13 @@ void LateUpdate ()
- Shader.SetGlobalVector("_FOWParams", p);
- Shader.SetGlobalTexture("_FOWTex0", mTexture0);
- Shader.SetGlobalTexture("_FOWTex1", mTexture1);
- if (!mThread.IsAlive)
- {
- Debug.LogError("FOWThread Dead; Restarting");
- mThread.Start();
- }
- }
- /// <summary>
- @@ -300,7 +307,14 @@ void ThreadUpdate ()
- {
- sw.Reset();
- sw.Start();
- UpdateBuffer();
- try
- {
- UpdateBuffer();
- }
- catch (System.Exception e)
- {
- Debug.LogWarning("FOWThreadException: " + e.ToString());
- }
- sw.Stop();
- if (debug) Debug.Log(sw.ElapsedMilliseconds);
- mElapsed = 0.001f * (float)sw.ElapsedMilliseconds;