Ver Fonte

more crash handling

Florian Mueller há 7 anos atrás
pai
commit
fcb7fbf824
2 ficheiros alterados com 30 adições e 14 exclusões
  1. BIN
      .vs/bbiwarg/v14/.suo
  2. 30 14
      bbiwarg/Input/InputProviding/InputProviderIntel.cs

BIN
.vs/bbiwarg/v14/.suo


+ 30 - 14
bbiwarg/Input/InputProviding/InputProviderIntel.cs

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
 using Emgu.CV;
 using Emgu.CV.Structure;
 using System.Drawing;
+using System.Threading;
 
 namespace BBIWARG.Input.InputProviding
 {
@@ -104,24 +105,39 @@ namespace BBIWARG.Input.InputProviding
                     Console.WriteLine("Trying to reinitialize the camera...");
                     Task<bool> initCameraTask = Task.Run(() => restartCamera());
                     crashed = !initCameraTask.Wait(TimeSpan.FromSeconds(5)) || !initCameraTask.Result;
+
+                    Thread.Yield();
+                }
+                else {
+
+                    crashed = !tryAcquireAndHandleFrame();
+                }
+            }
+        }
+
+        private bool tryAcquireAndHandleFrame()
+        {
+            try
+            {
+                //try to acquire new frame...
+                Task<bool> acquireFrameTask = Task.Run(() => acquireNewFrame());
+                //wait a second...
+                if (acquireFrameTask.Wait(TimeSpan.FromSeconds(4)) && acquireFrameTask.Result)
+                {
+                    //that worked, we should have a new frame by now...
+                    handleNewFrame();
+                    senseManager.ReleaseFrame();
+                    return true;
                 }
                 else {
-                    //try to acquire new frame...
-                    Task acquireFrameTask = Task.Run(() => acquireNewFrame());
-                    //wait a second...
-                    if (acquireFrameTask.Wait(TimeSpan.FromSeconds(1)))
-                    {
-                        //that worked, we should have a new frame by now...
-                        handleNewFrame();
-                        senseManager.ReleaseFrame();
-                    }
-                    else
-                    {
-                        //cam crashed. try to dispose and start again.
-                        crashed = true;
-                    }
+                    return false;
                 }
             }
+            catch (Exception e)
+            {
+                Console.WriteLine("Exception while acquiring frame: " + e);
+                return false;
+            }
         }
 
         private bool restartCamera()