AnKor
Topic Author
Posts: 8
Joined: 22 Jul 2022, 16:14

Threading requirements for Noesis::GUI::Shutdown

28 Jul 2022, 15:26

Hi!

We've ran into an issue (NoesisGUI 3.1.4) with Shutdown method reporting threading errors like this:
[NOESIS/I] Noesis Shutdown
[NOESIS/E] The calling thread (***) cannot access this DispatcherObject because a different thread (***) owns it
This happens if we use one thread for GUI:Init and GUI::Shutdown but create/update views in a different thread.

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:
[NOESIS/E] The calling thread (***) cannot access this Canvas because a different thread (***) owns it
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?
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.
 
User avatar
jsantos
Site Admin
Posts: 3545
Joined: 20 Jan 2012, 17:18
Contact:

Re: Threading requirements for Noesis::GUI::Shutdown

01 Aug 2022, 12:35

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!
 
AnKor
Topic Author
Posts: 8
Joined: 22 Jul 2022, 16:14

Re: Threading requirements for Noesis::GUI::Shutdown

01 Aug 2022, 17:27

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.
 
User avatar
jsantos
Site Admin
Posts: 3545
Joined: 20 Jan 2012, 17:18
Contact:

Re: Threading requirements for Noesis::GUI::Shutdown

01 Aug 2022, 21:23

Thank you! The attach is missing though.
 
AnKor
Topic Author
Posts: 8
Joined: 22 Jul 2022, 16:14

Re: Threading requirements for Noesis::GUI::Shutdown

02 Aug 2022, 10:08

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.
 
User avatar
jsantos
Site Admin
Posts: 3545
Joined: 20 Jan 2012, 17:18
Contact:

Re: Threading requirements for Noesis::GUI::Shutdown

02 Aug 2022, 10:40

I am pretty sure it is not a leak, but we will analyze your two examples and will come back. Thank you!
 
User avatar
sfernandez
Site Admin
Posts: 2664
Joined: 22 Dec 2011, 19:20

Re: Threading requirements for Noesis::GUI::Shutdown

02 Aug 2022, 20:19

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?
 
AnKor
Topic Author
Posts: 8
Joined: 22 Jul 2022, 16:14

Re: Threading requirements for Noesis::GUI::Shutdown

02 Aug 2022, 21:26

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!
 
User avatar
sfernandez
Site Admin
Posts: 2664
Joined: 22 Dec 2011, 19:20

Re: Threading requirements for Noesis::GUI::Shutdown

03 Aug 2022, 11:50

Thanks for the report, it is perfect.

Who is online

Users browsing this forum: No registered users and 0 guests