Fix plugin crash when nested scope occurs (#13556)

This commit is contained in:
Ted John 2020-12-10 01:38:15 +00:00 committed by GitHub
parent 22063ec8b9
commit 5a849ededf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -63,19 +63,25 @@ namespace OpenRCT2::Scripting
ScriptExecutionInfo& _execInfo;
std::shared_ptr<Plugin> _plugin;
std::shared_ptr<Plugin> _backupPlugin;
bool _backupIsGameStateMutable;
public:
PluginScope(ScriptExecutionInfo& execInfo, std::shared_ptr<Plugin> plugin, bool isGameStateMutable)
: _execInfo(execInfo)
, _plugin(plugin)
{
_backupPlugin = _execInfo._plugin;
_backupIsGameStateMutable = _execInfo._isGameStateMutable;
_execInfo._plugin = plugin;
_execInfo._isGameStateMutable = isGameStateMutable;
}
PluginScope(const PluginScope&) = delete;
~PluginScope()
{
_execInfo._plugin = nullptr;
_execInfo._isGameStateMutable = false;
_execInfo._plugin = _backupPlugin;
_execInfo._isGameStateMutable = _backupIsGameStateMutable;
}
};