Skip to content

Commit

Permalink
Merge pull request #520 from AndyTWF/fix-startup-crash
Browse files Browse the repository at this point in the history
fix: register eventbus in loader and updater
  • Loading branch information
AndyTWF authored May 14, 2023
2 parents abcb6bb + a23384e commit efd9610
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/loader/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "setting/SettingRepositoryFactory.h"
#include "curl/CurlApi.h"
#include "data/PluginDataLocations.h"
#include "eventhandler/MutableEventBus.h"
#include "eventhandler/StandardEventBusFactory.h"
#include "update/PluginVersion.h"

#ifndef UKCP_LOADER_API
Expand Down Expand Up @@ -35,6 +37,10 @@ UKCP_LOADER_API void EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInst
CreatePluginDataRoot(*windows);
UKControllerPlugin::Log::LoggerBootstrap::Bootstrap(*windows, L"loader");

// Create the event bus
UKControllerPluginUtils::EventHandler::MutableEventBus::SetFactory(
std::make_shared<UKControllerPluginUtils::EventHandler::StandardEventBusFactory>());

// Bootstrap the API, download the updater if we don't have it already and run it
UKControllerPlugin::Curl::CurlApi curl;
std::unique_ptr<UKControllerPlugin::Setting::SettingRepository> settings =
Expand Down Expand Up @@ -80,7 +86,9 @@ UKCP_LOADER_API void EuroScopePlugInInit(EuroScopePlugIn::CPlugIn** ppPlugInInst
throw std::exception("UKCP broke");
}
*ppPlugInInstance = pluginInstance;
UKControllerPluginUtils::EventHandler::MutableEventBus::Reset();
} catch (std::exception e) {
UKControllerPluginUtils::EventHandler::MutableEventBus::Reset();
ShutdownLogger();
throw;
}
Expand Down
1 change: 1 addition & 0 deletions src/loader/pch/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#pragma warning(pop)

#include <Windows.h>
#include <any>
#include <filesystem>
#include <fstream>
#include <set>
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/bootstrap/InitialisePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace UKControllerPlugin {
this->duplicatePlugin = std::make_unique<DuplicatePlugin>();
this->container = std::make_unique<PersistenceContainer>();

// Create the event bus.
// Create the event bus
UKControllerPluginUtils::EventHandler::MutableEventBus::SetFactory(
std::make_shared<UKControllerPluginUtils::EventHandler::StandardEventBusFactory>());

Expand Down
10 changes: 10 additions & 0 deletions src/updater/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "api/ApiFactory.h"
#include "setting/SettingRepositoryFactory.h"
#include "curl/CurlApi.h"
#include "eventhandler/MutableEventBus.h"
#include "eventhandler/StandardEventBusFactory.h"
#include "log/LoggerBootstrap.h"
#include "update/BootstrapReleaseChannelSettings.h"
#include "update/PluginVersion.h"
Expand Down Expand Up @@ -33,6 +35,10 @@ UKCP_UPDATER_API bool PerformUpdates()
windows = UKControllerPlugin::Windows::Bootstrap(dllInstance);
UKControllerPlugin::Log::LoggerBootstrap::Bootstrap(*windows, L"updater");

// Create the event bus
UKControllerPluginUtils::EventHandler::MutableEventBus::SetFactory(
std::make_shared<UKControllerPluginUtils::EventHandler::StandardEventBusFactory>());

// Bootstrap the API, download the updater if we don't have it already and run it
UKControllerPlugin::Curl::CurlApi curl;
std::unique_ptr<UKControllerPlugin::Setting::SettingRepository> settings =
Expand All @@ -46,6 +52,10 @@ UKCP_UPDATER_API bool PerformUpdates()
UKControllerPlugin::Duplicate::DuplicatePlugin duplicatePlugin;
const bool updatePeformed = CheckForUpdates(
*api, *windows, curl, duplicatePlugin.Duplicate(), settings->GetSetting("release_channel", "stable"));

// Shutdown event bus and logger
UKControllerPluginUtils::EventHandler::MutableEventBus::Reset();
ShutdownLogger();

return updatePeformed;
}
1 change: 1 addition & 0 deletions src/updater/pch/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// add headers that you want to pre-compile here
#include <Windows.h>
#include <any>
#include <filesystem>
#include <fstream>
#include <set>
Expand Down

0 comments on commit efd9610

Please sign in to comment.