Skip to content

Commit

Permalink
The declaration manager signals can be fired from any thread, which i…
Browse files Browse the repository at this point in the history
…s not a problem after reloadDecls, but it can be a problem during startup. If a UI module is initialised fast enough to receive the loaded signal we might run into threading problems.

Fix a couple of module dependencies.
  • Loading branch information
codereader committed Aug 21, 2022
1 parent fba9d09 commit c5d85b2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libs/wxutil/EntityClassChooser.cpp
Expand Up @@ -10,6 +10,7 @@
#include "i18n.h"
#include "ifavourites.h"
#include "ideclmanager.h"
#include "ui/iuserinterface.h"
#include "ui/imainframe.h"
#include "gamelib.h"

Expand Down Expand Up @@ -205,7 +206,7 @@ EntityClassChooser::EntityClassChooser(Purpose purpose) :
// Listen for defs-reloaded signal (cannot bind directly to
// ThreadedEntityClassLoader method because it is not sigc::trackable)
_defsReloaded = GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::EntityDef).connect(
sigc::mem_fun(this, &EntityClassChooser::loadEntityClasses)
[this]() { GlobalUserInterface().dispatch([this]() { loadEntityClasses(); }); }
);

// Setup the tree view and invoke threaded loader to get the entity classes
Expand Down
7 changes: 5 additions & 2 deletions radiant/ui/UserInterfaceModule.cpp
Expand Up @@ -105,7 +105,10 @@ const StringSet& UserInterfaceModule::getDependencies() const
MODULE_MRU_MANAGER,
MODULE_MAINFRAME,
MODULE_MOUSETOOLMANAGER,
MODULE_MAP
MODULE_MAP,
MODULE_PATCH,
MODULE_BRUSHCREATOR,
MODULE_TEXTOOL_SELECTIONSYSTEM,
};

return _dependencies;
Expand Down Expand Up @@ -237,7 +240,7 @@ void UserInterfaceModule::initialiseModule(const IApplicationContext& ctx)
#endif

_reloadMaterialsConn = GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::Material)
.connect([]() { GlobalMainFrame().updateAllWindows(); });
.connect([this]() { dispatch([]() { GlobalMainFrame().updateAllWindows(); }); });
}

void UserInterfaceModule::shutdownModule()
Expand Down
3 changes: 2 additions & 1 deletion radiant/ui/einspector/EntityInspector.cpp
Expand Up @@ -13,6 +13,7 @@
#include "ui/igroupdialog.h"
#include "ui/imainframe.h"
#include "itextstream.h"
#include "ui/iuserinterface.h"

#include "module/StaticModule.h"
#include "selectionlib.h"
Expand Down Expand Up @@ -513,7 +514,7 @@ void EntityInspector::onKeyValueSetChanged(const std::string& key, const std::st

void EntityInspector::onDefsReloaded()
{
refresh();
GlobalUserInterface().dispatch([this]() { refresh(); });
}

void EntityInspector::refresh()
Expand Down
9 changes: 6 additions & 3 deletions radiant/ui/mediabrowser/MediaBrowser.cpp
Expand Up @@ -9,6 +9,7 @@
#include "ishaders.h"
#include "ishaderclipboard.h"
#include "ifavourites.h"
#include "ui/iuserinterface.h"

#include "wxutil/MultiMonitor.h"
#include "wxutil/dataview/ResourceTreeViewToolbar.h"
Expand All @@ -31,6 +32,7 @@

#include <functional>
#include "string/predicate.h"
#include "ui/UserInterfaceModule.h"

namespace ui
{
Expand Down Expand Up @@ -133,12 +135,12 @@ void MediaBrowser::setSelection(const std::string& selection)

void MediaBrowser::onMaterialDefsLoaded()
{
_treeView->Populate();
GlobalUserInterface().dispatch([this]() { _treeView->Populate(); });
}

void MediaBrowser::onMaterialDefsUnloaded()
{
_treeView->Clear();
GlobalUserInterface().dispatch([this]() { _treeView->Clear(); });
}

void MediaBrowser::_onTreeViewSelectionChanged(wxDataViewEvent& ev)
Expand Down Expand Up @@ -180,7 +182,8 @@ const StringSet& MediaBrowser::getDependencies() const
MODULE_SHADERCLIPBOARD,
MODULE_MAINFRAME,
MODULE_FAVOURITES_MANAGER,
MODULE_MAP
MODULE_MAP,
MODULE_USERINTERFACE,
};

return _dependencies;
Expand Down

0 comments on commit c5d85b2

Please sign in to comment.