Jump to content

Cannot add into world from another thread


photo

Recommended Posts

Hello,

In Unigine's Editor plugin implementation, there is no "update" function. So I made an update function which is executed on a thread which starts in init and terminates in shutdown.

Apparently, nodes cannot be added to the world on a thread other that the main thread. Why? Is there a workaround for this?

void add_dummy_to_selected()
{
  auto dummy = Unigine::NodeDummy::create();
  dummy->setShowInEditorEnabled(true);
  dummy->setOwner(false);

  if (Editor::SelectorNodes* snodes = Editor::Selection::getSelectorNodes())
  {
    auto nodes = snodes->getNodes();
    if (nodes.size() >= 1)
      nodes[0]->addChild(dummy);
  }
}
void add_dummy_with_thread()
{
  std::thread thread = std::thread(&add_dummy_to_selected);
  thread.join();
}

In the example above, using add_dummy_to_selected works, but add_dummy_with_thread doesn't.

Thanks in advance

Link to comment
×
×
  • Create New...