Skip to content

Commit 0f17140

Browse files
committed
Add startup delay to prevent crashes on session load
1 parent 9daed07 commit 0f17140

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

‎Concealment/ConcealmentPlugin.cs‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public sealed class ConcealmentPlugin : TorchPluginBase, IWpfPlugin
4545
private readonly List<ConcealGroup> _intersectGroups;
4646
private MyDynamicAABBTreeD _concealedAabbTree;
4747
private bool _settingsChanged;
48+
private bool _ready;
4849

4950
public ConcealmentPlugin()
5051
{
@@ -86,15 +87,28 @@ public override void Update()
8687
if (MyAPIGateway.Session == null || !Settings.Data.Enabled)
8788
return;
8889

89-
if (_counter % (ulong)Settings.Data.ConcealInterval == 0)
90-
ConcealGrids(Settings.Data.ConcealDistance);
91-
if (_counter % (ulong)Settings.Data.RevealInterval == 0)
92-
RevealGrids(Settings.Data.RevealDistance);
93-
_counter += 1;
90+
if (_ready)
91+
{
92+
if (_counter % (ulong)Settings.Data.ConcealInterval == 0)
93+
ConcealGrids(Settings.Data.ConcealDistance);
94+
if (_counter % (ulong)Settings.Data.RevealInterval == 0)
95+
RevealGrids(Settings.Data.RevealDistance);
96+
_counter += 1;
97+
}
9498

9599
if (_init || MyAPIGateway.TerminalControls == null)
96100
return;
97101

102+
//Make sure the game physics has time to initialize.
103+
var delayTimer = new System.Timers.Timer
104+
{
105+
AutoReset = false,
106+
Interval = 5000,
107+
};
108+
109+
delayTimer.Elapsed += (sender, args) => _ready = true;
110+
delayTimer.Start();
111+
98112
var keepAliveAction = MyAPIGateway.TerminalControls.CreateAction<IMyRemoteControl>("Concealment.KeepAlive");
99113
keepAliveAction.Action = KeepAlive;
100114
MyAPIGateway.TerminalControls.AddAction<IMyRemoteControl>(keepAliveAction);

0 commit comments

Comments
 (0)