Browse Source

...and catching AccessViolations

Florian Mueller 7 years ago
parent
commit
44df91dadb
2 changed files with 20 additions and 2 deletions
  1. BIN
      .vs/bbiwarg/v14/.suo
  2. 20 2
      bbiwarg/Input/InputProviding/InputProviderIntel.cs

BIN
.vs/bbiwarg/v14/.suo


+ 20 - 2
bbiwarg/Input/InputProviding/InputProviderIntel.cs

@@ -4,6 +4,7 @@ using Emgu.CV.Structure;
 using System.Timers;
 using System.Threading;
 using System.Diagnostics;
+using System.Runtime.ExceptionServices;
 
 namespace BBIWARG.Input.InputProviding
 {
@@ -71,6 +72,7 @@ namespace BBIWARG.Input.InputProviding
         int startId = 0;
         Stopwatch startTimeWatch;
 
+        [HandleProcessCorruptedStateExceptions]
         public void start()
         {
             Console.WriteLine("starting new AppDomain (" + startId +")...");
@@ -90,7 +92,16 @@ namespace BBIWARG.Input.InputProviding
 
             scheduledForRestart = false;
             startTimeWatch = Stopwatch.StartNew();
-            wrapper.run();
+
+            try
+            {
+                wrapper.run();
+            }
+            catch (System.AccessViolationException)
+            {
+                Console.WriteLine("Camera caused corrupted process state.");
+                errorstate = true;
+            }
 
             checkExitErrorstate();
         }
@@ -106,7 +117,7 @@ namespace BBIWARG.Input.InputProviding
                     return;
                 }
                     
-                startTimeWatch.Stop();
+                //startTimeWatch.Stop();
 
                 //we have crashed. Kill the app domain and try again.
                 Console.WriteLine("Killing AppDomain (" + domain.FriendlyName + ")...");
@@ -144,6 +155,13 @@ namespace BBIWARG.Input.InputProviding
         internal void newFrame(int currentFrameID, Image<Gray, ushort> dImg)
         {
             errorstate = false;
+            if (startTimeWatch != null)
+            {
+                Console.WriteLine("done");
+                startTimeWatch.Stop();
+                startTimeWatch = null;
+            }
+
             NewFrameEvent(this, new NewFrameEventArgs(currentFrameID, dImg));
         }
     }