Permalink
Browse files

Some bug fixes

  • Loading branch information...
1 parent e8ceee6 commit 9636189c826b40a480c17aaf07e77f358aa3396a @theone1984 theone1984 committed May 26, 2011
@@ -96,8 +96,8 @@ protected override void ProcessWorkerThreadInternally()
}
catch (SocketException e)
{
- if (!IsNormalDisconnectError(e))
- throw e;
+ //if (!IsNormalDisconnectError(e))
+ //throw e;
}
}
catch (Exception e)
@@ -354,7 +354,16 @@ private void TryToPingDrone()
options.DontFragment = true;
byte[] data = Encoding.ASCII.GetBytes("This is a test");
- pingSender.SendAsync(droneIpAddress, pingTimeout, data, options);
+ bool sent = false;
+ while (!sent)
+ {
+ try
+ {
+ pingSender.SendAsync(droneIpAddress, pingTimeout, data, options);
+ sent = true;
+ }
+ catch (Exception) { }
+ }
}
private void ProcessPingResult(PingCompletedEventArgs e)
@@ -69,13 +69,21 @@ protected override void ProcessWorkerThread()
do
{
- if (IsKeepAliveSignalNeeded())
+ try
+ {
+ if (IsKeepAliveSignalNeeded())
+ SendMessage(1);
+
+ byte[] buffer = client.Receive(ref endpoint);
+
+ if (buffer.Length > 0)
+ videoUtils.ProcessByteStream(buffer);
+ }
+ catch (SocketException e)
+ {
+ Console.WriteLine("Socket exception occured: " + e.ErrorCode);
SendMessage(1);
-
- byte[] buffer = client.Receive(ref endpoint);
-
- if (buffer.Length > 0)
- videoUtils.ProcessByteStream(buffer);
+ }
}
while (!workerThreadEnded);
}
@@ -342,24 +342,34 @@ private void UpdateVideoImage()
{
Bitmap newImage = CopyBitmap((Bitmap)droneControl.BitmapImage);
- PerformStopSignDetection(newImage);
- UpdateVisualImage(newImage);
+ if (newImage != null)
+ {
+ PerformStopSignDetection(newImage);
+ UpdateVisualImage(newImage);
+ }
}
}
private Bitmap CopyBitmap(Bitmap image)
{
- int width = image.Width;
- int height = image.Height;
- Rectangle rectangleToCopy = new Rectangle(0, 0, width, height);
+ try
+ {
+ int width = image.Width;
+ int height = image.Height;
+ Rectangle rectangleToCopy = new Rectangle(0, 0, width, height);
+
+ Bitmap newImage = new Bitmap(width, height);
+ using (Graphics g = Graphics.FromImage(newImage))
+ {
+ g.DrawImage(image, rectangleToCopy, rectangleToCopy, GraphicsUnit.Pixel);
+ }
- Bitmap newImage = new Bitmap(width, height);
- using (Graphics g = Graphics.FromImage(newImage))
+ return newImage;
+ }
+ catch (Exception)
{
- g.DrawImage(image, rectangleToCopy, rectangleToCopy, GraphicsUnit.Pixel);
+ return null;
}
-
- return newImage;
}
private void PerformStopSignDetection(Bitmap image)

0 comments on commit 9636189

Please sign in to comment.