Skip to content

Commit 2f5fecd

Browse files
committed
fix multithread bug from logging in paralell.foreach
1 parent 402924c commit 2f5fecd

File tree

9 files changed

+12
-31
lines changed

9 files changed

+12
-31
lines changed

AvaGui/Models/FileSystemItemGroup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Avalonia;
21
using Avalonia.Data.Converters;
32
using OpenLoco.ObjectEditor.Data;
43
using OpenLoco.ObjectEditor.Objects;

AvaGui/Models/ObjectEditorModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ public class ObjectEditorModel : ReactiveObject // todo: only viewmodels should
5858

5959
public static string SettingsFile => Path.Combine(SettingsPath, "settings.json");
6060

61-
public ObservableCollection<LogLine> LoggerObservableLogs => ((Logger)Logger).Logs;
61+
public ObservableCollection<LogLine> LoggerObservableLogs = new();
6262

6363
public ObjectEditorModel()
6464
{
6565
Logger = new Logger();
66+
LoggerObservableLogs = new ObservableCollection<LogLine>(((Logger)Logger).Logs);
67+
6668
LoadSettings(SettingsFile, Logger);
6769
}
6870

AvaGui/Models/UiSoundObject.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using OpenLoco.ObjectEditor.Types;
2-
using System.ComponentModel;
32

43
namespace AvaGui.Models
54
{

AvaGui/Typedefs.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,2 @@
1-
global using uint8_t = System.Byte;
2-
global using int8_t = System.SByte;
3-
global using uint16_t = System.UInt16;
41
global using int16_t = System.Int16;
5-
global using int32_t = System.Int32;
62
global using uint32_t = System.UInt32;
7-
global using size_t = System.UInt32;
8-
global using char_t = System.Byte;
9-
global using string_id = System.UInt16;
10-
global using image_id = System.UInt32;
11-
global using object_id = System.Byte;
12-
global using Speed16 = System.Int16;
13-
global using Speed32 = System.Int32;
14-
global using MicroZ = System.Byte;
15-
global using SoundObjectId = System.Byte;

AvaGui/ViewModels/ImageTableViewModel.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
using System.Threading.Tasks;
1717
using System.Windows.Input;
1818
using System.ComponentModel;
19-
using System.Collections.ObjectModel;
2019
using OpenLoco.ObjectEditor.Types;
21-
using AvaGui.Models;
22-
using Avalonia.Media;
23-
using Avalonia.Markup.Xaml.Converters;
24-
using Avalonia.Data.Converters;
2520

2621
namespace AvaGui.ViewModels
2722
{

AvaGui/ViewModels/ObjectEditorViewModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
using OpenLoco.ObjectEditor.Headers;
99
using System.Reactive;
1010
using OpenLoco.ObjectEditor.Logging;
11-
using System.Linq;
1211
using System.Threading.Tasks;
1312
using Core.Objects.Sound;
14-
using System.Drawing;
15-
using Avalonia.Media;
1613

1714
namespace AvaGui.ViewModels
1815
{

AvaGui/Views/MainWindow.axaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Avalonia.Controls;
2-
using AvaGui.Models;
3-
using AvaGui.ViewModels;
42

53
namespace AvaGui.Views
64
{

Core/DatFileParsing/SawyerStreamReader.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,13 @@ static void ValidateLocoStruct(S5Header s5Header, ILocoStruct locoStruct, ILogge
165165

166166
try
167167
{
168-
if (s5Header.SourceGame == SourceGame.Vanilla && !OriginalObjectFiles.Names.ContainsKey(s5Header.Name.Trim()))
168+
if (s5Header.SourceGame == SourceGame.Vanilla)
169169
{
170-
warnings.Add($"\"{s5Header.Name}\" is not a vanilla object but is marked as such.");
170+
var s5Name = s5Header.Name.Trim();
171+
if (!OriginalObjectFiles.Names.TryGetValue(s5Name, out var value) || s5Header.Checksum != value)
172+
{
173+
warnings.Add($"\"{s5Header.Name}\" is not a vanilla object but is marked as such.");
174+
}
171175
}
172176

173177
if (!locoStruct.Validate())

Shared/Logger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.ObjectModel;
1+
using System.Collections.Concurrent;
22

33
namespace OpenLoco.ObjectEditor.Logging
44
{
@@ -15,15 +15,15 @@ public override string ToString()
1515

1616
public class Logger : ILogger
1717
{
18-
public readonly ObservableCollection<LogLine> Logs = [];
18+
public readonly ConcurrentQueue<LogLine> Logs = [];
1919
public LogLevel Level = LogLevel.Info;
2020

2121
public event EventHandler<LogAddedEventArgs>? LogAdded;
2222

2323
public void Log(LogLevel level, string message, string callerMemberName = "")
2424
{
2525
var log = new LogLine(DateTime.Now, level, callerMemberName, message);
26-
Logs.Add(log);
26+
Logs.Enqueue(log);
2727

2828
if (Level <= level)
2929
{

0 commit comments

Comments
 (0)