-
- bkunikowski
- Posts: 12
- Joined:
Problem with UI thread (cannot access this Border because a different thread owns it)
I'm trying to integrate more and more stuff from Noesis to custom engine. Currently I have problem with threading. My engine uses different workers to initialize and then update many systems. One of them is UI system (Noesis). So due to there are many different threads, Noesis comes with ERROR that cannot access some element due to different thread owns it.
So I created dedicated thread and delegate all Noesis Views creation and updates to this thread, but still have info that my Main Thread owns some stuff.
Could you explain what does it mean that element is own by thread? What else should I do in such case?
Error:
The calling thread (53740) cannot access this Border because a different thread (6184) owns it
So I created dedicated thread and delegate all Noesis Views creation and updates to this thread, but still have info that my Main Thread owns some stuff.
Could you explain what does it mean that element is own by thread? What else should I do in such case?
Error:
The calling thread (53740) cannot access this Border because a different thread (6184) owns it
-
- bkunikowski
- Posts: 12
- Joined:
Re: Problem with UI thread (cannot access this Border because a different thread owns it)
Xaml I use to view creation has good thread id. LoadXaml is called just before CreateView function on the same dedicated thread. The error appears when I want to execute view->SetSize(size.x, size.y) function later in some frame stuff scope.
-
- bkunikowski
- Posts: 12
- Joined:
Re: Problem with UI thread (cannot access this Border because a different thread owns it)
I'm tried with that piece of code executed on my UI thread.
Explanation:
m_queue is queue with tasks to execute on UI thread.
What interesting I've checked xaml->CheckAccess() and it returns true and xaml->GetThreadId() returns my UI thread ID.
However execution of that piece of code results with the same error as previous on SetSize line
Is view instances always bound to Main Thread? Because it always refer to Main thread as a thread that owns stuff.
Code: Select all
m_queue->syncTask<void>([this]() {
Noesis::Ptr<Noesis::FrameworkElement> xaml = Noesis::GUI::LoadXaml<Noesis::FrameworkElement>(m_xamlResource->resourcePath().c_str());
auto view = Noesis::GUI::CreateView(xaml);
view->SetSize(1920, 1080);
});m_queue is queue with tasks to execute on UI thread.
What interesting I've checked xaml->CheckAccess() and it returns true and xaml->GetThreadId() returns my UI thread ID.
However execution of that piece of code results with the same error as previous on SetSize line
Is view instances always bound to Main Thread? Because it always refer to Main thread as a thread that owns stuff.
-
- bkunikowski
- Posts: 12
- Joined:
Re: Problem with UI thread (cannot access this Border because a different thread owns it)
Ok, it looks that loading default styles also needs to be done on UI thread. That's the reason.
Re: Problem with UI thread (cannot access this Border because a different thread owns it)
Sorry for the late reply. As you noticed, the first time an instance is accessed on a thread, it becomes tied to that thread. From then on, every access to that instance must come from the same thread.
If you’re certain that the instance is only being touched by one thread at a time (and there are no concurrent accesses), you can safely ignore the warning. We’re aware this can be inconvenient, especially since many studios run Noesis inside jobs that may execute on different threads each frame. Because of this, we plan to add an option to disable that warning in the future.
If you’re certain that the instance is only being touched by one thread at a time (and there are no concurrent accesses), you can safely ignore the warning. We’re aware this can be inconvenient, especially since many studios run Noesis inside jobs that may execute on different threads each frame. Because of this, we plan to add an option to disable that warning in the future.
Who is online
Users browsing this forum: Bing [Bot] and 4 guests