Center mouse click crashes applications on some PCs with an Arithmetic Overflow Exception #2715

Closed
starkna opened this Issue Oct 27, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@starkna

starkna commented Oct 27, 2016

What steps will reproduce this issue?

This issue has occurred on several of our customer PCs when running our application as a 64-bit process. I cannot personally reproduce the issue, but the customers have verified the fix below resolved the problem for them.

An arithmetic overflow exception occurs, and the stack trace indicates the problem stemming from the Utilities.cs file, specifically the GET_X_LPARAM and GET_Y_LPARAM methods.

We have changed the methods to read as follows:

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    public static int GET_X_LPARAM(IntPtr lParam)
    {
        return LOWORD(Environment.Is64BitProcess ? lParam.ToInt64() : lParam.ToInt32());
    }

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    public static int GET_Y_LPARAM(IntPtr lParam)
    {
        return HIWORD(Environment.Is64BitProcess ? lParam.ToInt64() : lParam.ToInt32());
    }

We have also added an overload to each of HIWORD and LOWORD to accommodate the long parameter.

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    public static int HIWORD(long i)
    {
        return (short)((i >> 16) & 0xFFFF);
    }

    [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    public static int LOWORD(long i)
    {
        return (short)(i & 0xFFFF);
    }

Environment

  • MahApps.Metro v1.2.4
  • Windows 7
  • Visual Studio 2015
  • .NET Framework 4.6

@punker76 punker76 self-assigned this Oct 27, 2016

@punker76 punker76 added this to the 1.4.0 milestone Oct 27, 2016

@punker76 punker76 added the Bug label Oct 27, 2016

@punker76

This comment has been minimized.

Show comment
Hide comment
@punker76

punker76 Oct 27, 2016

Member

@starkna I changed it and check now for 64 bit process. So check 1.4.0-ALPHA025 to test it out.

Member

punker76 commented Oct 27, 2016

@starkna I changed it and check now for 64 bit process. So check 1.4.0-ALPHA025 to test it out.

@punker76 punker76 closed this Oct 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment