Threading requirements for Noesis::GUI::Shutdown
Hi!
We've ran into an issue (NoesisGUI 3.1.4) with Shutdown method reporting threading errors like this:
According to your doc https://www.noesisengine.com/docs/Gui.C ... orial.html a View object has to be accessed from the owner thread, but it is possible to use separate views with different threads. It doesn't say anything about Init and Shutdown and we assumed these don't care about specific thread (otherwise which thread would it be?).
We've also noticed that Init and Shutdown has to be called on the same thread. Failing to do this gives an error even without creating any views:
It looks like some UI objects are being created and not released until shutdown and thus having shutdown in a separate thread violates their threading requirements.
We've ran into an issue (NoesisGUI 3.1.4) with Shutdown method reporting threading errors like this:
This happens if we use one thread for GUI:Init and GUI::Shutdown but create/update views in a different thread.[NOESIS/I] Noesis Shutdown
[NOESIS/E] The calling thread (***) cannot access this DispatcherObject because a different thread (***) owns it
According to your doc https://www.noesisengine.com/docs/Gui.C ... orial.html a View object has to be accessed from the owner thread, but it is possible to use separate views with different threads. It doesn't say anything about Init and Shutdown and we assumed these don't care about specific thread (otherwise which thread would it be?).
We've also noticed that Init and Shutdown has to be called on the same thread. Failing to do this gives an error even without creating any views:
Overall it is not a problem to have init/shutdown in the same thread as views - we plan to use a single update thread anyway, but could you advice if this is expected behavior and not some sort of memory leak?[NOESIS/E] The calling thread (***) cannot access this Canvas because a different thread (***) owns it
It looks like some UI objects are being created and not released until shutdown and thus having shutdown in a separate thread violates their threading requirements.
Re: Threading requirements for Noesis::GUI::Shutdown
You shouldn't be getting these errors. It is recommended to have Init() and Shutdown() in the same thread (not mandatory, but recommended for performance) but you can have views in other threads. This seems to be a problem with unfrozen resources coming from the theme or internal caches (for example, solid color brushes are cached).
Unfortunately, we are unable to reproduce this. Could you please try to reproduce in one of our examples and indicate the steps? Thank you!
Unfortunately, we are unable to reproduce this. Could you please try to reproduce in one of our examples and indicate the steps? Thank you!
Re: Threading requirements for Noesis::GUI::Shutdown
I've attached Main.cpp from SDK's Integration sample.
It has minimal changes - I've just moved Init and Shutdown calls into "AThread" routine that works in a separate thread.
I even disabled creation of a Views, but just having LoadApplicationResources already causes multiple error at Shutdown.
Moving things around (like having LoadApplicationResources in the Init thread) only makes things worse.
This is not exactly our scenario though.
What we observe is that only certain controls or actions (withdefault NoesisTheme) cause errors at shutdown - like right clicking on a TextBox (to show context menu) or just having a ScrollViewer.
Obviously we don't plan to use NoesisTheme but we are wondering what goes wrong.
It has minimal changes - I've just moved Init and Shutdown calls into "AThread" routine that works in a separate thread.
I even disabled creation of a Views, but just having LoadApplicationResources already causes multiple error at Shutdown.
Moving things around (like having LoadApplicationResources in the Init thread) only makes things worse.
This is not exactly our scenario though.
What we observe is that only certain controls or actions (withdefault NoesisTheme) cause errors at shutdown - like right clicking on a TextBox (to show context menu) or just having a ScrollViewer.
Obviously we don't plan to use NoesisTheme but we are wondering what goes wrong.
Re: Threading requirements for Noesis::GUI::Shutdown
Thank you! The attach is missing though.
Re: Threading requirements for Noesis::GUI::Shutdown
Sorry about this (facepalm :) ), but for some reason I can't attach a file, The forum shows error triangle after upload, but doesn't tell why.
Anyway, I have prepared two examples based on your Integration sample (the one that displays Settings menu):
Here I just moved Init/Shutdown into a separate thread: https://1drv.ms/u/s!AvmtwF9vPtwVgo9ly5A ... A?e=FEDYLN
And this one is more involved, I kept Init/Shutdown and Render in the main thread, but moved view creation and update into a separate thread (there's also a message queue to process events in that thread): https://1drv.ms/u/s!AvmtwF9vPtwVgo9kTps ... Q?e=ef3MeH
As I say our main concern is not even the threading, we can move Init/Shutdown into the update thread to silence these errors.
We are more concerned that certain objects (context menu, scrollviewer) seem to leave something in memory until shutdown, even after views are released. If it is some sort of cache, then it is probably ok, but if views may cause memory leak it may be a problem.
Anyway, I have prepared two examples based on your Integration sample (the one that displays Settings menu):
Here I just moved Init/Shutdown into a separate thread: https://1drv.ms/u/s!AvmtwF9vPtwVgo9ly5A ... A?e=FEDYLN
And this one is more involved, I kept Init/Shutdown and Render in the main thread, but moved view creation and update into a separate thread (there's also a message queue to process events in that thread): https://1drv.ms/u/s!AvmtwF9vPtwVgo9kTps ... Q?e=ef3MeH
As I say our main concern is not even the threading, we can move Init/Shutdown into the update thread to silence these errors.
We are more concerned that certain objects (context menu, scrollviewer) seem to leave something in memory until shutdown, even after views are released. If it is some sort of cache, then it is probably ok, but if views may cause memory leak it may be a problem.
Re: Threading requirements for Noesis::GUI::Shutdown
I am pretty sure it is not a leak, but we will analyze your two examples and will come back. Thank you!
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Threading requirements for Noesis::GUI::Shutdown
Hi AnKor, thank you for the examples, we were able to reproduce the errors and to find the source of the problem.
It is related to the control templates defined in the theme, there are some objects that are not correctly detached from the creation thread.
Could you please report it in our bugtracker and we will fix it?
It is related to the control templates defined in the theme, there are some objects that are not correctly detached from the creation thread.
Could you please report it in our bugtracker and we will fix it?
Re: Threading requirements for Noesis::GUI::Shutdown
Interesting.
I have created https://www.noesisengine.com/bugs/view.php?id=2392 - hope it is enough, I'm not good at this :)
Thank you!
I have created https://www.noesisengine.com/bugs/view.php?id=2392 - hope it is enough, I'm not good at this :)
Thank you!
-
sfernandez
Site Admin
- Posts: 2991
- Joined:
Re: Threading requirements for Noesis::GUI::Shutdown
Thanks for the report, it is perfect.
Who is online
Users browsing this forum: Google [Bot] and 17 guests