BASE: Reset the keymapper on RTL with dynamic plugins enabled

When returning to the launcher with dynamic plugins enabled, the config manager
is re-created, invalidating the pointers the keymapper keeps to the
configuration domains.

Fixes #11348.
This commit is contained in:
Bastien Bouclet 2020-02-09 07:18:13 +01:00
parent 678c9fd532
commit 3567c4f159
3 changed files with 18 additions and 0 deletions

View File

@ -45,11 +45,20 @@ Keymapper::Keymapper(EventManager *eventMan) :
}
Keymapper::~Keymapper() {
clear();
}
void Keymapper::clear() {
for (KeymapArray::iterator it = _keymaps.begin(); it != _keymaps.end(); it++) {
delete *it;
}
_keymaps.clear();
delete _backendDefaultBindings;
_backendDefaultBindings = nullptr;
delete _hardwareInputs;
_hardwareInputs = nullptr;
}
void Keymapper::registerHardwareInputSet(HardwareInputSet *inputs) {
@ -143,6 +152,7 @@ void Keymapper::setEnabledKeymapType(Keymap::KeymapType type) {
_enabledKeymapType = type;
}
List<Event> Keymapper::mapEvent(const Event &ev) {
if (!_enabled) {
List<Event> originalEvent;

View File

@ -120,6 +120,11 @@ public:
*/
void setEnabled(bool enabled) { _enabled = enabled; }
/**
* Clear all the keymaps and hardware input sets
*/
void clear();
/**
* Return a HardwareInput pointer for the given event
*/

View File

@ -358,6 +358,7 @@ static void setupKeymapper(OSystem &system) {
using namespace Common;
Keymapper *mapper = system.getEventManager()->getKeymapper();
mapper->clear();
// Query the backend for hardware keys and default bindings and register them
HardwareInputSet *inputSet = system.getHardwareInputSet();
@ -568,6 +569,8 @@ extern "C" int scummvm_main(int argc, const char * const argv[]) {
PluginManager::instance().unloadPluginsExcept(PLUGIN_TYPE_ENGINE, NULL, false);
// reallocate the config manager to get rid of any fragmentation
ConfMan.defragment();
// The keymapper keeps pointers to the configuration domains. It needs to be reinitialized.
setupKeymapper(system);
#endif
// Did an error occur ?