-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multithreaded ImDrawList usage causing flicks #6167
Comments
Only if actual AddXXX functions are called at the same time, which never worked even before (as they would manipulate VtxBuffer IdxBuffer etc.) so I don't think this is your issue and you are looking at and fixing a wrong thing. FYI this is likely incorrect: |
EDIT You can use |
I've spent whole day to determine what causes it.
You can simply reproduce this bug with CreateThread winapi function and code above AddRect calls:
And other thread can also access this variable while menu is building vertexes to pass to d3d_impl Other ImDrawList AddXXX functions that doesnt use TempBuffer works fine, without glitches |
Yes, but version with allocators worked fine with that.
Edit: |
If you mean calling EndFrame() or Render(), you should not call them from a separate thread. Call it before copying the draw list.
It was only accidental luck that it worked before. |
This is ambiguous, please clarify.
I repeat, you can never call ImDrawList functions from those threads. This was never allowed. |
Sorry for multiple messages. I think I understand what you meant. This last example suggests you want to append to different draw lists at the same time in different thread. (A)
Notice this is called GetDrawListSharedData() and the type is ImDrawListSharedData. It would still be lucky that your ImGui code / main thread wasn't manipulating other fields of the ImDrawListSharedData structure while adding to ImDrawList from another thread. This is different from copying a drawlist so it can be rendered later (B), which is more common when a Render thread runs in parallel with an Update thread. For this, you can swap or clone your drawlist in the Update thread after calling EndFrame()/Render(), then store that data and let the Render thread process is later. If I understand you are trying to do (A) ? |
Yes, you are right. Here is working example of what I mean https://github.com/Skreamex/mtrenderer_issue |
You may initialize your ImDrawListSharedData instance with a copy of Other ImGui functions may perfectly interfere with this data, e.g. if you call ImGui::PushFont() from one thread and use the drawlist with same shared data from another thread, the ImDrawListSharedData::Font/FontSize fields will change. So your solution is not correct. To slightly increase discoverability I have amend the old Changelog:
|
Yeah, but in not my case. I use ImDrawList to render my data, I dont use GUI.
What field I should copy from main shared data before call my Begin/End functions? I create and use fonts only in my renderer class |
You'll need to investigate how the fields are set to find out where. |
Ok, thanks for information. |
…DrawData itself. Faclitate user-manipulation of the array (#6406, #4879, #1878) + deep swap. (#6597, #6475, #6167, #5776, #5109, #4763, #3515, #1860) + Metrics: avoid misleadingly iterating all layers of DrawDataBuilder as everything is flattened into Layers[0] at this point. # Conflicts: # imgui.cpp # imgui_internal.h
Version/Branch of Dear ImGui:
Version: v1.89.3
Branch: features/shadows and master
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_dx9.cpp + imgui_impl_win32.cpp
Operating System: Windows 10
My Issue/Question:
Hello. I was using 1.84 WIP to use separated drawlists.
Fist thread fills some draw data to draw list, locks mutex and copies to rendering list
Main d3d9 thread
Begin() function
End() function
Get data to draw
D3D call looks like
After upgrade I ran into problem that all vertexes are flickering
I've started to search what causes it and after some compares realized that ImDrawListSharedData has new member
So it means two thread accesses same TempBuffer variable in same time
I've done simpe quick fix to solve problem
TempBuffer member now function
And some replacements like
Now it works fine without any glitches
The text was updated successfully, but these errors were encountered: