1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-25 07:44:38 +01:00

Fix #14160: Game crashs when registering shortcuts

This commit is contained in:
Ted John
2021-02-23 22:18:00 +00:00
parent aedd93ef33
commit 52dffb83c2
4 changed files with 8 additions and 6 deletions

View File

@@ -131,8 +131,10 @@ RegisteredShortcut* ShortcutManager::GetShortcut(std::string_view id)
void ShortcutManager::RemoveShortcut(std::string_view id)
{
Shortcuts.erase(std::remove_if(
Shortcuts.begin(), Shortcuts.end(), [id](const RegisteredShortcut& shortcut) { return shortcut.Id == id; }));
Shortcuts.erase(
std::remove_if(
Shortcuts.begin(), Shortcuts.end(), [id](const RegisteredShortcut& shortcut) { return shortcut.Id == id; }),
Shortcuts.end());
}
bool ShortcutManager::IsPendingShortcutChange() const

View File

@@ -23,7 +23,7 @@ namespace OpenRCT2::Scripting
{
std::optional<CustomTool> ActiveCustomTool;
std::vector<CustomToolbarMenuItem> CustomMenuItems;
std::vector<CustomShortcut> CustomShortcuts;
std::vector<std::unique_ptr<CustomShortcut>> CustomShortcuts;
CustomShortcut::CustomShortcut(
std::shared_ptr<Plugin> owner, std::string_view id, std::string_view text, const std::vector<std::string>& bindings,
@@ -130,7 +130,7 @@ namespace OpenRCT2::Scripting
auto& shortcuts = CustomShortcuts;
for (auto it = shortcuts.begin(); it != shortcuts.end();)
{
if (it->Owner == owner)
if ((*it)->Owner == owner)
{
it = shortcuts.erase(it);
}

View File

@@ -94,7 +94,7 @@ namespace OpenRCT2::Scripting
extern std::optional<CustomTool> ActiveCustomTool;
extern std::vector<CustomToolbarMenuItem> CustomMenuItems;
extern std::vector<CustomShortcut> CustomShortcuts;
extern std::vector<std::unique_ptr<CustomShortcut>> CustomShortcuts;
void InitialiseCustomMenuItems(ScriptEngine& scriptEngine);
void InitialiseCustomTool(ScriptEngine& scriptEngine, const DukValue& dukValue);

View File

@@ -327,7 +327,7 @@ namespace OpenRCT2::Scripting
}
auto callback = desc["callback"];
CustomShortcuts.emplace_back(owner, id, text, bindings, callback);
CustomShortcuts.emplace_back(std::make_unique<CustomShortcut>(owner, id, text, bindings, callback));
}
catch (const DukException&)
{