Skip to content
This repository
Browse code

Some bug fixes

  • Loading branch information...
commit 9636189c826b40a480c17aaf07e77f358aa3396a 1 parent e8ceee6
Thomas Endres authored May 26, 2011
4  ARDroneControlLibrary/Network/NetworkWorker.cs
@@ -96,8 +96,8 @@ protected override void ProcessWorkerThreadInternally()
96 96
                 }
97 97
                 catch (SocketException e)
98 98
                 {
99  
-                    if (!IsNormalDisconnectError(e))
100  
-                        throw e;
  99
+                    //if (!IsNormalDisconnectError(e))
  100
+                        //throw e;
101 101
                 }
102 102
             }
103 103
             catch (Exception e)
11  ARDroneControlLibrary/Workers/NetworkConnector.cs
@@ -354,7 +354,16 @@ private void TryToPingDrone()
354 354
             options.DontFragment = true;
355 355
             byte[] data = Encoding.ASCII.GetBytes("This is a test");
356 356
 
357  
-            pingSender.SendAsync(droneIpAddress, pingTimeout, data, options);
  357
+            bool sent = false;
  358
+            while (!sent)
  359
+            {
  360
+                try
  361
+                {
  362
+                    pingSender.SendAsync(droneIpAddress, pingTimeout, data, options);
  363
+                    sent = true;
  364
+                }
  365
+                catch (Exception) { }
  366
+            }
358 367
         }
359 368
 
360 369
         private void ProcessPingResult(PingCompletedEventArgs e)
20  ARDroneControlLibrary/Workers/VideoDataRetriever.cs
@@ -69,13 +69,21 @@ protected override void ProcessWorkerThread()
69 69
 
70 70
             do
71 71
             {
72  
-                if (IsKeepAliveSignalNeeded())
  72
+                try
  73
+                {
  74
+                    if (IsKeepAliveSignalNeeded())
  75
+                        SendMessage(1);
  76
+
  77
+                    byte[] buffer = client.Receive(ref endpoint);
  78
+
  79
+                    if (buffer.Length > 0)
  80
+                        videoUtils.ProcessByteStream(buffer);
  81
+                }
  82
+                catch (SocketException e)
  83
+                {
  84
+                    Console.WriteLine("Socket exception occured: " + e.ErrorCode);
73 85
                     SendMessage(1);
74  
-
75  
-                byte[] buffer = client.Receive(ref endpoint);
76  
-
77  
-                if (buffer.Length > 0)
78  
-                    videoUtils.ProcessByteStream(buffer);
  86
+                }
79 87
             }
80 88
             while (!workerThreadEnded);
81 89
         }
30  ARDroneUI_Detection_Forms/MainForm.cs
@@ -342,24 +342,34 @@ private void UpdateVideoImage()
342 342
             {
343 343
                 Bitmap newImage = CopyBitmap((Bitmap)droneControl.BitmapImage);
344 344
 
345  
-                PerformStopSignDetection(newImage);
346  
-                UpdateVisualImage(newImage);
  345
+                if (newImage != null)
  346
+                {
  347
+                    PerformStopSignDetection(newImage);
  348
+                    UpdateVisualImage(newImage);
  349
+                }
347 350
             }
348 351
         }
349 352
 
350 353
         private Bitmap CopyBitmap(Bitmap image)
351 354
         {
352  
-            int width = image.Width;
353  
-            int height = image.Height;
354  
-            Rectangle rectangleToCopy = new Rectangle(0, 0, width, height);
  355
+            try
  356
+            {
  357
+                int width = image.Width;
  358
+                int height = image.Height;
  359
+                Rectangle rectangleToCopy = new Rectangle(0, 0, width, height);
  360
+
  361
+                Bitmap newImage = new Bitmap(width, height);
  362
+                using (Graphics g = Graphics.FromImage(newImage))
  363
+                {
  364
+                    g.DrawImage(image, rectangleToCopy, rectangleToCopy, GraphicsUnit.Pixel);
  365
+                }
355 366
 
356  
-            Bitmap newImage = new Bitmap(width, height);
357  
-            using (Graphics g = Graphics.FromImage(newImage))
  367
+                return newImage;
  368
+            }
  369
+            catch (Exception)
358 370
             {
359  
-                g.DrawImage(image, rectangleToCopy, rectangleToCopy, GraphicsUnit.Pixel);
  371
+                return null;
360 372
             }
361  
-
362  
-            return newImage;
363 373
         }
364 374
 
365 375
         private void PerformStopSignDetection(Bitmap image)

0 notes on commit 9636189

Please sign in to comment.
Something went wrong with that request. Please try again.