Skip to content

Commit 01c0eee

Browse files
committed
Automatic merge of T1.5.1-1885-g12b1a74d5 and 8 pull requests
- Pull request #570 at 362e4e7: glTF 2.0 support with PBR lighting - Pull request #1085 at 37e2817: updates key commands for Train Operations window and also Daylight Offset - Pull request #1086 at e10390b: Add Settings Exporter tool (copy settings to INI, etc) - Pull request #1094 at e6e95f1: Blended Braking Compatibility and Effectiveness Improvements - Pull request #1095 at 55111e9: Make Control Confirmations Fade Out in Real Time - Pull request #1082 at 5845a1a: Allow variable water level in glass gauge - Pull request #1081 at 689494b: Brake cuts power unification - Pull request #1091 at b0c622b: Automatic speed control
10 parents fafecd0 + 12b1a74 + 362e4e7 + 37e2817 + e10390b + e6e95f1 + 55111e9 + 5845a1a + 689494b + b0c622b commit 01c0eee

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Source/RunActivity/Viewer3D/Popups/MessagesWindow.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public override void PrepareFrame(ElapsedTime elapsedTime, bool updateFull)
139139
}
140140

141141
foreach (var message in Messages)
142-
message.LabelShadow.Color.A = message.LabelText.Color.A = (byte)MathHelper.Lerp(255, 0, MathHelper.Clamp((float)((Owner.Viewer.Simulator.GameTime - message.EndTime) / FadeTime), 0, 1));
142+
if (message.LabelShadow != null && message.LabelText != null) // It seems LabelShadow and LabelText aren't guaranteed to be initialized, causing rare crashes
143+
message.LabelShadow.Color.A = message.LabelText.Color.A = (byte)MathHelper.Lerp(255, 0, MathHelper.Clamp((float)((Owner.Viewer.RealTime - message.EndTime) / FadeTime), 0, 1));
143144
}
144145

145146
class Message
@@ -184,7 +185,7 @@ public void AddMessage(string text, double duration)
184185
public void AddMessage(string key, string text, double duration)
185186
{
186187
var clockTime = Owner.Viewer.Simulator.ClockTime;
187-
var gameTime = Owner.Viewer.Simulator.GameTime;
188+
var realTime = Owner.Viewer.RealTime;
188189
while (true)
189190
{
190191
// Store the original list and make a clone for replacing it thread-safely.
@@ -196,18 +197,18 @@ public void AddMessage(string key, string text, double duration)
196197

197198
// Clean out any existing duplicate key and expired messages.
198199
newMessages = (from m in newMessages
199-
where (String.IsNullOrEmpty(key) || m.Key != key) && m.EndTime + FadeTime > Owner.Viewer.Simulator.GameTime
200+
where (String.IsNullOrEmpty(key) || m.Key != key) && m.EndTime + FadeTime > realTime
200201
select m).ToList();
201202

202203
// Add the new message.
203-
newMessages.Add(new Message(key, String.Format("{0} {1}", FormatStrings.FormatTime(clockTime), text), existingMessage != null ? existingMessage.StartTime : gameTime, gameTime + duration));
204+
newMessages.Add(new Message(key, String.Format("{0} {1}", FormatStrings.FormatTime(clockTime), text), existingMessage != null ? existingMessage.StartTime : realTime, realTime + duration));
204205

205206
// Sort the messages.
206207
newMessages = (from m in newMessages
207208
orderby m.StartTime descending
208209
select m).ToList();
209210

210-
// Thread-safely switch from the old list to the new list; we've only suceeded if the previous (return) value is the old list.
211+
// Thread-safely switch from the old list to the new list; we've only succeeded if the previous (return) value is the old list.
211212
if (Interlocked.CompareExchange(ref Messages, newMessages, oldMessages) == oldMessages)
212213
break;
213214
}

0 commit comments

Comments
 (0)