Closed MichaelKv closed 2 years ago
Regarding Create/DestroyContext
, you are doing it correctly -- once on startup before your ImGui/application loop starts, and once at the end when the application shuts down. No worries there, and you don't need to call it on data reload (there is a better way; keep reading).
FYI, ImPlot assigns the next unused colormap color to new plot items (i.e. label ID not seen yet) on their first frame, and caches and reuses that color on subsequent frames. So regarding memory corruption, there could be a cache bug but I have not seen it and no one else has ever reported it.
There are two reasons I can come up with that would cause the behavior you are seeing:
1) your PlotLine
label ID is changing between data reloads -- this would be viewed as a new PlotItem and thus be assigned a new colormap color (even if you're still only plotting one line)
2) you are accidently reusing the same title ID for two or more of your N BeginPlots
-- aside from causing other odd issues, this could cause the issue you are seeing if all of your PlotLine
label IDs are unique
Can you confirm if either of theses are the case? If not can you show a little more code?
And to be clear, when you say ...
but colors for PlotLine may change for different channels randomly.
... do you mean they change randomly on data reload or quite literally randomly, without any cause?
Finally, you can try calling the following function and passing NULL
on data reload.
IMPLOT_API void BustColorCache(const char* plot_title_id = NULL);
This will bust all color caching across all plots. I would rather figure out why things aren't working instead of relying on this, so please let me know if investigating (1) and (2) is fruitful.
Thanks for explanation. They will not help much because I have not gotten used to dig into the thirdparties – they shall just work from scratch that is not definitely the case with ImGUI/ImPlot. The colors change the following way: I have several dozens of BeginPlots that does not fit to the screen and scroll (btw, it means there are a lot of problems with ImPlotCond_Always/ImGuiCond_None/ImGuiCond_Once and the pair ImPlotCond_Always/ImGuiCond_None behaves radically different opposed to what you documentation claims, but I have just figured out that ImPlotCond_Always somehow works for me and stopped investigations); all PlotLine (one per BeginPlot) colors are the same (default); I reload the same file (or different) and some (different each time) PlotLines begin to draw a different (orange) color. I do not think it has something to do with the data reloading itself. I can load the same file – the same data, the same structure of plots, etc., but the different colors. I have already solved the issue with DestroyContext/CreateContext on each my data reload. I cannot send a code because it is an in-house tool that may reveal and harm something (you know). But the idea is as above – nothing special or peculiar. I even do the paging/scaling/decimation/etc. myself because it is rather specific. All the data I plot fits the single plot width (the amount of samples). I do not think I will be able to help you with IDs – I just do not understand the system so far (so you must forgive me that I find it extremely cumbersome). And I am sorry to say I am totally useless in the way that I am API/tools developer and all my previous GUIs were in MS Access VBA. I would like to take the opportunity
-- Michael
As I said, DestroyContext/CreateContext
is NOT the solution you are looking for. I am almost certain this is a simple mistake with an easy fix, but your reluctance to understand the API and inability to offer reproducable code (btw, a minimal example demonstrating your issue would suffice) makes it difficult for me to help you any further. I am closing this issue until you can provide more information or can address my points above.
Regarding examples that you can copy/paste, we have over 2k lines of example code in implot_demo.cpp
.
Hello. I have a kind of multichannel signal viewer that draws N BeginPlots with one (so far) PlotLine. I call ImPlot::CreateContext at the beginning of the program and ImPlot::DestroyContext() at the end. While my program works I can load another data with different channels amount, etc, and I do not call DestroyContext/CreateContext in this very case. Everything works fine but colors for PlotLine may change for different channels randomly. They are usually the original PlotLine color and orange. I do not set colors and use defaults. All other colors in BeginPlot part (axes, grid, etc) are OK. Such a behavior makes me think there is a memory corruption happens somewhere inside ImPlot. Or probably I shall call DestroyContext/CreateContext on my data reload. Can you, please, help me with this color change? I also believe a more classic scheme, like ImPlot plot; plot. BeginPlot(…); plot.PlotLine(…); etc. could really eliminate such a problem as a class. But DestroyContext/CreateContext are OK, provided I know how to use them properly.
-- Michael