Question

first of all, I have been learning Microsoft Surface for about 1-2 months now and my project requires me to look into incorporating the use of a VNC viewer into my Surface Application.

I have looked into VNCSharp and VNCSharpWpf from VNC control for WPF application and I'm currently using VNCSharpWpf as it has better user interaction in the WPF environment although the performance is somewhat lacking compared to the viewers out there.

Here is my question, is there any difference between Microsoft Surface WPF and the default WPF in how they handle framebuffer/threads ?

I noticed that when the client attempts to draw the rectangle in the Surface environment, it will cause an exception where by the rectangle to be updated has 0 width and height.

However, when I test it on the sample code the author of VNCSharpWPF provides (WPF on Window ), the error never occur.

I tried to workaround by setting and if clause to only draw if the width and height of the rectangle decoded is not 0. Although it prevents the application from crashing, it will results in dead pixel around the screen whenever there are changes in the screen in the server-end.

I've been stuck with this situation for 1-2 weeks already and have ran out of ideas and is in need of some guidance on where I should look into

Or is there is any cool VNC viewer/server out there that I can use for my Surface project that I've missed out ?

Was it helpful?

Solution

I've been having the same issue with VNCSharp WPF on a PC, and when tested VNC Sharp for WinForms, then it worked OK.

Furthermore, When I've tested VNCSharp for WPF on Debug, then it works OK, but failed on Release.

I've wasted several hours debugging it (I've learned some parts of the VNC protocol for that matter, since I've found out that it somehow reads the width and the height of the remote device from the wrong location in the netowrk stream).

The bug is related to floats comparison. It depends on the machine you have (it might work well on some machines and on others it might not)

Please look at VncClient, Line 349:

  if (rfb.ServerVersion == 3.8) rfb.ReadSecurityFailureReason();

If you, while debugging, put a breakpoint there, you will see that rfb.ServerVersion is 3.8f

ServerVersion returns a calcualted float:

    public float ServerVersion {
        get {
            return (float) verMajor + (verMinor * 0.1f);
        }
    }

You should expect that since ServerVersion is 3.8, then it will execute ReadSecurityFailureReason which reads some extra bytes that are needed for the code to work, but on Release (Ctrl+F5, since in Visual Studio Release, while the code is being debugged, it will probably work OK) those extra bytes will not be read, so the width and height will be read from the wrong location on the stream, causing it to be 0px over 0px

For demontrating my point, please take the following code, and compile it as x86 (I'm assuming that you have an x64 machine and an x64 OS, since this is the situation here):

    class Program
{
    static void Main(string[] args)
    {
        SomeVersion someVersion = new SomeVersion(3, 8);

        if (someVersion.Version == 3.8f)
        {
            Console.WriteLine("Version is 3.8");
        }

        Console.ReadLine();
    }

}

public class SomeVersion
{
    private int _major;
    private int _minor;

    public SomeVersion(int major, int minor)
    {
        _major = major;
        _minor = minor;
    }

    public float Version
    {
        get
        {
            return (float)_major + (_minor * 0.1f);
        }
    }
}

Run the code in Debug x86 (both with visual studio debugger and with Ctrl+F5) You should see that you get the message: "Version is 3.8" on both cases. Now change it to Release x86... Run it with F5. You should get the message. Now run it with Ctrl + F5... WTF??, no message!

In order to fix the bug in the Vnc Sharp WPF, I've took the class RfcProtocol, and added another function:

    public bool CompareVersion(int major, int minor)
    {
        return major == verMajor && minor == verMinor;
    }

Now on VNC Client (both line 188 and 349), I've changed the code so it will compare using the new function, instead of comparing 2 floats.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top