Sign in to follow this  

PeekMessage and muti thread engine

Recommended Posts

Posted (edited)

Hi. I am designing a simple multi thread game engine, in brief, game thread updates game objects while the render thread is rendering previous frame, but the problems is that  when I use PeekMessage() in game thread and move mouse or click on window it do something like a refresh and make a frame delay or unfinished

thanks in advance

Edited by UPO33

Share this post


Link to post
Share on other sites

Been a while since used the Win32 message pumps that low down but if memory serves then your message pump must live in the main app thread, not is separate threads that you start. 

Share this post


Link to post
Share on other sites

Been a while since used the Win32 message pumps that low down but if memory serves then your message pump must live in the main app thread, not is separate threads that you start. 

 

There is no need for that, in fact, it is usually less of a hassle to create a thread that will create the window and own the message loop so it can runs even smooth even if the application lag or something.

 

With d3d11, there was some weirdness in alt tab management and you had to call all swap chain function from the window thread for safety if i remember correctly, but that is all.

 

I also usually create a separate thread with a message only window to listen for raw input device when using high rate polling mouse.

 

But anyway, more details are necessary to help the OP.

Share this post


Link to post
Share on other sites

With d3d11, there was some weirdness in alt tab management and you had to call all swap chain function from the window thread for safety if i remember correctly, but that is all.

 

Not necessarily true, but it is important that window messages are being processed during swapchain operation. If the swapchain APIs are being used on the window's thread, the WndProc is invoked recursively, otherwise, the swapchain APIs will block until the WndProc has processed the messages.

 

Also, a recently reported/fixed bug to be aware of: If using fullscreen swapchains, the swapchain should enter fullscreen on a thread which is processing messages with NULL, or Present() should be called on the same thread that entered fullscreen. There is an occasional issue where Present() can send a message to a window created during fullscreen transitions, and if the thread that owns that window isn't pumping messages for it, you can deadlock. As far as I'm aware, this bug has existed since Win7 or Win8, and has not been fixed in the wild yet.

Share this post


Link to post
Share on other sites
Posted (edited)

guys I solved it. I moved PeekMessage before Swapchain and it works. it seems that peekMessage must not be called during swapchain

thats my game loop now :

bool GTTick()
{
	bool result = true;

	result = GameWindow::PeekMessages(); //PeekMessage(..)
	if (!result) return false;

	EnqueueRenderCommand([this]() {
		Render();
		PresentSawpChain();
	});

	UpdateWorld();
	
	///////////////wait for render command to finish
	EnqueueRenderCommandAndWait([]() {});

	return result;
}
Edited by UPO33

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this