From abd31f9a946168e8fb1c2e2cbcd1f94b27297618 Mon Sep 17 00:00:00 2001 From: d3agle Date: Tue, 14 Apr 2015 04:58:48 -0500 Subject: [PATCH] Fixed Remote Desktop Bug Fixed a bug where changing resolutions while Remote Desktop is running would crash both the client + server. This fix ensures that the Remote Desktop features continues to run accurately after changing resolutions on the client. --- Client/Core/Commands/CommandHandler.cs | 18 +++++++++++++----- Server/Core/Commands/CommandHandler.cs | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Client/Core/Commands/CommandHandler.cs b/Client/Core/Commands/CommandHandler.cs index df703255..571883c2 100644 --- a/Client/Core/Commands/CommandHandler.cs +++ b/Client/Core/Commands/CommandHandler.cs @@ -233,11 +233,19 @@ public static void HandleRemoteDesktop(Packets.ServerPackets.Desktop command, Cl using (MemoryStream stream = new MemoryStream()) { - StreamCodec.CodeImage(bmpdata.Scan0, - new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), - new Size(LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), LastDesktopScreenshot.PixelFormat, - stream); - new Packets.ClientPackets.DesktopResponse(stream.ToArray(), StreamCodec.ImageQuality, StreamCodec.Monitor).Execute(client); + try + { + StreamCodec.CodeImage(bmpdata.Scan0, + new Rectangle(0, 0, LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), + new Size(LastDesktopScreenshot.Width, LastDesktopScreenshot.Height), LastDesktopScreenshot.PixelFormat, + stream); + new Packets.ClientPackets.DesktopResponse(stream.ToArray(), StreamCodec.ImageQuality, StreamCodec.Monitor).Execute(client); + } + catch + { + new Packets.ClientPackets.DesktopResponse(null, StreamCodec.ImageQuality, StreamCodec.Monitor).Execute(client); + StreamCodec = null; + } } LastDesktopScreenshot.UnlockBits(bmpdata); diff --git a/Server/Core/Commands/CommandHandler.cs b/Server/Core/Commands/CommandHandler.cs index 334f3192..87066c00 100644 --- a/Server/Core/Commands/CommandHandler.cs +++ b/Server/Core/Commands/CommandHandler.cs @@ -111,6 +111,24 @@ public static void HandleRemoteDesktopResponse(Client client, DesktopResponse pa if (client.Value.FrmRdp == null) return; + if (packet.Image == null) + { + try + { + client.Value.FrmRdp.Invoke((MethodInvoker)delegate + { + client.Value.FrmRdp.picDesktop.Image = (Bitmap)client.Value.LastDesktop; + }); + } + catch + { } + + client.Value.LastDesktop = null; + client.Value.LastDesktopSeen = true; + + return; + } + // we can not dispose all bitmaps here, cause they are later used again in `client.Value.LastDesktop` if (client.Value.LastDesktop == null) {