PDA

View Full Version : WIN32 ClanLib 0.9 Message Queue has_messages()



rombust
09-12-2008, 12:44 PM
Currently, the Basic2D example on the Win32 platform does not work.

You cannot move the window on Vista.

The problem is caused by:
bool CL_DisplayMessageQueue::has_messages()

Currently, the code is:

bool CL_DisplayMessageQueue::has_messages()
{
return wait(0);
}

If i replace the function with:


bool CL_DisplayMessageQueue::has_messages()
{
CL_DisplayWindowMessage message = peek_message(false);
return (!message.is_null());
}

The Basic2D example works

But why?
I would have thought wait(0) would have been a better function to use.

(I have not changed the SVN)

Magnus Norddahl
09-14-2008, 05:56 AM
That is a very good question.

I know that when you click outside the client area (i.e. if you start resizing the window), then Windows will block during the GetMessage call and perform its own modal loop.

Now, I would personally expect MsgWaitForMultipleEvents to also unblock in the situations where such a modal loop is pending (since it is started by a mouse click in the non-client area), but your alternative version of has_messages() seem to indicate it does not - or that we have a bug in how we use MsgWaitForMultipleEvents. I really hope it is the later because the former would put us in big trouble.

rombust
09-15-2008, 07:41 AM
I think that i have found the problem:

Change:
DWORD result = MsgWaitForMultipleObjects(0, 0, FALSE, timeout_win32, QS_ALLEVENTS);

To
DWORD result = MsgWaitForMultipleObjectsEx(0, 0, timeout_win32, QS_ALLEVENTS, MWMO_INPUTAVAILABLE);

"MsgWaitForMultipleObjectsEx does not return if there is unread input of the specified type in the message queue after the thread has called a function to check the queue, unless you use the MWMO_INPUTAVAILABLE flag."

After making that change, the examples work

I have not applied the patch until conformation. (Attached is the patch)

rombust
09-15-2008, 11:04 AM
Patch applied to SVN.

It makes the DiceWar GUI nice and fast :)

Magnus Norddahl
09-15-2008, 06:01 PM
Oh very nice, you found the bug that was totally puzzling me. Great work. :)