Fix crash due to mutating `ToolManager._tools` while enumerating it

resolves #3983
This commit is contained in:
YoshiRulz 2024-08-06 02:11:17 +10:00
parent cdf79d3593
commit 9f5a5d8593
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 6 additions and 6 deletions

View File

@ -479,7 +479,7 @@ namespace BizHawk.Client.EmuHawk
/// <typeparam name="T">Type of tools to check</typeparam>
public T FirstOrNull<T>(Predicate<T> condition) where T : class
{
foreach (var tool in _tools)
foreach (var tool in _tools) // not bothering to copy here since `condition` is expected to have no side-effects
{
if (tool.IsActive && tool is T specialTool && condition(specialTool))
{
@ -594,7 +594,7 @@ namespace BizHawk.Client.EmuHawk
var unavailable = new List<IToolForm>();
foreach (var tool in _tools)
foreach (var tool in _tools.ToArray()) // copy because a tool may open another
{
SetBaseProperties(tool);
if (ServiceInjector.UpdateServices(_emulator.ServiceProvider, tool)
@ -748,7 +748,7 @@ namespace BizHawk.Client.EmuHawk
public void UpdateToolsBefore()
{
foreach (var tool in _tools)
foreach (var tool in _tools.ToArray()) // copy because a tool may open another
{
if (tool.IsActive)
{
@ -759,7 +759,7 @@ namespace BizHawk.Client.EmuHawk
public void UpdateToolsAfter()
{
foreach (var tool in _tools)
foreach (var tool in _tools.ToArray()) // copy because a tool may open another
{
if (tool.IsActive)
{
@ -770,7 +770,7 @@ namespace BizHawk.Client.EmuHawk
public void FastUpdateBefore()
{
foreach (var tool in _tools)
foreach (var tool in _tools.ToArray()) // copy because a tool may open another
{
if (tool.IsActive)
{
@ -781,7 +781,7 @@ namespace BizHawk.Client.EmuHawk
public void FastUpdateAfter()
{
foreach (var tool in _tools)
foreach (var tool in _tools.ToArray()) // copy because a tool may open another
{
if (tool.IsActive)
{