Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix game crash on load #1676

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ This changelog includes all versions and major variants of the mod going all the

> Date format: dd/mm/yyyy

#### TM:PE V[11.7.1.2](https://github.com/CitiesSkylinesMods/TMPE/compare/11.7.1.1...11.7.1.2) STABLE, 11/10/2022

- [Fixed] Game crash on load (krzychu124)
- [Steam] [TM:PE v11 STABLE](https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252)

#### TM:PE V11.7.1.2 TEST, 11/10/2022

- [Fixed] Game crash on load (krzychu124)
- [Steam] [TM:PE v11 TEST](https://steamcommunity.com/sharedfiles/filedetails/?id=2489276785)

#### TM:PE V[11.7.1.1](https://github.com/CitiesSkylinesMods/TMPE/compare/11.7.0.1...11.7.1.1) STABLE, 10/10/2022
- [Meta] TM:PE 11.7.1.1 TEST branch released as STABLE - huge thanks to our beta testers!
- [New] Dead-end lane connections #1613, #1213 (kianzarrin)
Expand Down
7 changes: 7 additions & 0 deletions TLM/TLM/Resources/whats_new.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[Version] 11.7.1.2
[Released] Oct 11th 2022
[Link] tmpe-v11712-stable-11102022
[Stable]
[Fixed] Game crash on load (krzychu124)
[/Version]

[Version] 11.7.1.1
[Released] Oct 10th 2022
[Link] tmpe-v11711-stable-10102022
Expand Down
16 changes: 15 additions & 1 deletion TLM/TLM/UI/Helpers/CheckboxOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace TrafficManager.UI.Helpers {
using TrafficManager.State;
using CSUtil.Commons;
using System.Collections.Generic;
using ColossalFramework.Threading;
using JetBrains.Annotations;
using TrafficManager.Util;
using UnityEngine;

public class CheckboxOption : SerializableUIOptionBase<bool, UICheckBox, CheckboxOption> {
Expand Down Expand Up @@ -74,7 +76,19 @@ public override bool Value {
if (!value && _propagatesFalseTo != null)
PropagateTo(_propagatesFalseTo, false);

if (HasUI) _ui.isChecked = value;
if (Shortcuts.IsMainThread()) {
if (HasUI) {
_ui.isChecked = value;
}
} else {
SimulationManager.instance
.m_ThreadingWrapper
.QueueMainThread(() => {
if (HasUI) {
_ui.isChecked = value;
}
});
}
}
}

Expand Down
15 changes: 13 additions & 2 deletions TLM/TLM/UI/Helpers/DropDownOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TrafficManager.UI.Helpers {
using System;
using System.Linq;
using TrafficManager.API.Traffic.Enums;
using TrafficManager.Util;

public class DropDownOption<TEnum> : SerializableUIOptionBase<TEnum, UIDropDown, DropDownOption<TEnum>>
where TEnum : struct, Enum, IConvertible {
Expand Down Expand Up @@ -50,8 +51,18 @@ public override TEnum Value {
set {
if (values_.Contains(value)) {
base.Value = value;
if (HasUI) {
_ui.selectedIndex = IndexOf(value);
if (Shortcuts.IsMainThread()) {
if (HasUI) {
_ui.selectedIndex = IndexOf(value);
}
} else {
SimulationManager.instance
.m_ThreadingWrapper
.QueueMainThread(() => {
if (HasUI) {
_ui.selectedIndex = IndexOf(value);
}
});
}
} else {
Log.Error($"unrecognised value:{value} for enum:{typeof(TEnum).Name}");
Expand Down
1 change: 1 addition & 0 deletions TLM/TLM/UI/Helpers/SerializableUIOptionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace TrafficManager.UI.Helpers {
using ICities;
using System.Reflection;
using System;
using System.Threading;
using TrafficManager.State;
using JetBrains.Annotations;
using TrafficManager.Lifecycle;
Expand Down
18 changes: 15 additions & 3 deletions TLM/TLM/UI/Helpers/SliderOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace TrafficManager.UI.Helpers {
using CSUtil.Commons;
using UnityEngine;
using System;
using TrafficManager.Util;

public class SliderOption : SerializableUIOptionBase<float, UISlider, SliderOption> {

Expand Down Expand Up @@ -70,9 +71,20 @@ public override float Value {

Log.Info($"SliderOption.Value: `{FieldName}` changed to {value}");

if (HasUI) {
_ui.value = value;
UpdateTooltip();
if (Shortcuts.IsMainThread()) {
if (HasUI) {
_ui.value = value;
UpdateTooltip();
}
} else {
SimulationManager.instance
.m_ThreadingWrapper
.QueueMainThread(() => {
if (HasUI) {
_ui.value = value;
UpdateTooltip();
}
});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/UI/WhatsNew/WhatsNew.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace TrafficManager.UI.WhatsNew {

public class WhatsNew {
// bump and update what's new changelogs when new features added
public static readonly Version CurrentVersion = new Version(11,7,1,1);
public static readonly Version CurrentVersion = new Version(11,7,1,2);

private const string WHATS_NEW_FILE = "whats_new.txt";
private const string RESOURCES_PREFIX = "TrafficManager.Resources.";
Expand Down
3 changes: 3 additions & 0 deletions TLM/TLM/Util/Shortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ namespace TrafficManager.Util {
using UnityEngine;
using ColossalFramework.UI;
using System.Diagnostics;
using ColossalFramework.Threading;

internal static class Shortcuts {
internal static bool InSimulationThread() =>
System.Threading.Thread.CurrentThread == SimulationManager.instance.m_simulationThread;

internal static bool IsMainThread() => Dispatcher.currentSafe == Dispatcher.mainSafe;

/// <summary>
/// returns a new calling Clone() on all items.
/// </summary>
Expand Down