浏览代码

even more error handling

Florian Mueller 8 年之前
父节点
当前提交
583f45c0f6

二进制
.vs/bbiwarg/v14/.suo


+ 1 - 0
bbiwarg/Input/InputProviding/IInputProvider.cs

@@ -65,5 +65,6 @@ namespace BBIWARG.Input.InputProviding
         void initialize();
         void start();
         void stop();
+        bool IsCrashed();
     }
 }

+ 4 - 0
bbiwarg/Input/InputProviding/InputProviderIisu.cs

@@ -127,6 +127,10 @@ namespace BBIWARG.Input.InputProviding
             run();
         }
 
+        public bool IsCrashed() {
+            return false;
+        }
+
         /// <summary>
         /// Stops the device.
         /// </summary>

+ 21 - 6
bbiwarg/Input/InputProviding/InputProviderIntel.cs

@@ -71,14 +71,19 @@ namespace BBIWARG.Input.InputProviding
             keepActive();
         }
 
-        private void initCameraDevice()
+        private bool initCameraDevice()
         {
             senseManager = PXCMSenseManager.CreateInstance();
             PXCMVideoModule.DataDesc ddesc = new PXCMVideoModule.DataDesc();
             ddesc.deviceInfo.streams = PXCMCapture.StreamType.STREAM_TYPE_DEPTH;
             senseManager.EnableStreams(ddesc);
 
-            senseManager.Init();
+            var initStatus = senseManager.Init();
+
+            if (initStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) {
+                Console.WriteLine("Could not init camera. Result: " + initStatus);
+                return false;
+            }
 
             PXCMPointF32 fov = senseManager.captureManager.device.QueryDepthFieldOfView();
             FieldOfViewHorizontal = fov.x;
@@ -86,6 +91,8 @@ namespace BBIWARG.Input.InputProviding
 
             lowConfidenceValue = senseManager.captureManager.device.QueryDepthLowConfidenceValue();
             senseManager.captureManager.device.SetDepthConfidenceThreshold((UInt16)Parameters.ConfidenceImageMinThreshold);
+
+            return true;
         }
 
         public void stop()
@@ -106,10 +113,12 @@ namespace BBIWARG.Input.InputProviding
                     Task<bool> initCameraTask = Task.Run(() => restartCamera());
                     crashed = !initCameraTask.Wait(TimeSpan.FromSeconds(5)) || !initCameraTask.Result;
 
-                    Thread.Yield();
+                    if (crashed) {
+                        Console.WriteLine("Something went wrong during init. Waiting a few seconds to cool down...");
+                        Thread.Sleep(2000);
+                    }
                 }
                 else {
-
                     crashed = !tryAcquireAndHandleFrame();
                 }
             }
@@ -146,14 +155,17 @@ namespace BBIWARG.Input.InputProviding
             {
                 crashed = false;
                 senseManager.Dispose();
-                initCameraDevice();
+                return initCameraDevice();
             }
             catch (Exception)
             {
                 return false;
             }
+        }
 
-            return true;
+        public bool IsCrashed()
+        {
+            return crashed;
         }
 
         protected bool acquireNewFrame() {
@@ -185,6 +197,9 @@ namespace BBIWARG.Input.InputProviding
             senseManager.Dispose();
         }
 
+        
+
+
         private void handleNewFrame()
         {
             PXCMCapture.Sample sample = senseManager.QuerySample();

+ 3 - 0
bbiwarg/Output/DebugOutput/DebugWindow.cs

@@ -180,6 +180,9 @@ namespace BBIWARG.Output.DebugOutput
         /// <param name="e">the event arguments</param>
         private void update(object sender, EventArgs e)
         {
+            if (inputProvider.IsCrashed())
+                return;
+
             Utility.Timer.start("DebugWindow.update");
 
             if (!inputProvider.IsActive)