PeekMessage and muti thread engine

Started by
4 comments, last by UPO33 7 years, 3 months ago

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

Advertisement

Sounds like you are doing something wrong, but unfortunately without some code surrounding the problem context all we can do is guess.

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.

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.

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.

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;
}

This topic is closed to new replies.

Advertisement