Jump to content
  • Advertisement
Sign in to follow this  

[.net] A weird crash in x64 Release mode....

This topic is 2894 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

OK, so just to get this out of the way:
It runs in x86 in both release and debug mode inside of the IDE.
It runs in x86 in both release and debug mode outside of the IDE.
It runs in x64 in both release and debug mode inside of the IDE.
It runs in x64 in debug mode outside of the IDE.
It crashes in x64 in release mode outside of the IDE.

So, I'm experiencing a very weird issue with my little test application. And by issue, I mean it crashes... hard. No exception (at least, nothing that I could catch), just the "Blah Blah has stopped responding..." message. As I stated above it crashes ONLY when I run the app in x64, release mode and outside of the IDE.

I've narrowed it down to my p/invoke PeekMessage call. So, I need the brilliant minds here to look at the crap I've written and tell me if I'm doing it right. Because, seriously, I'm about to fucking lose my mind. I've tried this on 2 computers and they both exhibit the same behaviour. I'm a little concerned that this could be a .NET 4.0 bug.

Anyway, here's my p/invoke code. Please let me know if you see anything odd or just plain stupid:

Here's the call to PeekMessage:

private static bool PeekMessage()
MSG message = new MSG(); // Message to retrieve.

return Win32API.PeekMessage(ref message, IntPtr.Zero, 0, 0, PeekMessageFlags.NoRemove);

Here's PeekMessage (NOTE: The suppress security attribute is on the class definition, so it is being applied):
/// <summary>
/// Function to process window messages.
/// </summary>
/// <remarks>See the MSDN documentation for a detailed description.</remarks>
/// <param name="msg">Message block to retrieve.</param>
/// <param name="hwnd">Window to retrieve messages from, FALSE for all.</param>
/// <param name="wFilterMin">Minimum message.</param>
/// <param name="wFilterMax">Maximum message.</param>
/// <param name="flags">Flags for the function.</param>
/// <returns>TRUE if messages are ready for processing, FALSE if not.</returns>
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool PeekMessage(ref MSG msg, IntPtr hwnd, uint wFilterMin, uint wFilterMax, PeekMessageFlags flags);

Here's the MSG:

internal struct MSG
/// <summary>Window handle.</summary>
public IntPtr hwnd;
/// <summary>Message to process.</summary>
public uint Message;
/// <summary>Window message parameter 1.</summary>
public uint wParam;
/// <summary>Window message parameter 2.</summary>
public uint lParam;
/// <summary>Time message was sent?</summary>
public uint time;
/// <summary>Mouse pointer position.</summary>
public Point pt;

And finally, the PeekMessageFlags:

internal enum PeekMessageFlags
/// <summary>Keep message on the message queue.</summary>
NoRemove = 0,
/// <summary>Remove message from the queue.</summary>
Remove = 1,
/// <summary>Do not yield execution to waiting threads.</summary>
NoYield = 2

So, if you see anything not quite right, please let me know. I'd hate for this to not be my fault.

Sorry if it's not detailed enough, if you need more info, just leave a note. It's midnight and I'm exhausted.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!