Space Engineers

Space Engineers

Skimt's Grid Power Chart
This topic has been locked
Skimt  [developer] 29 Nov, 2022 @ 4:37pm
System.OverflowException [Resolved]
ArcWolf reported the following on the 26th of November 2022.

Thread: 1 -> Exception occurred: System.OverflowException: TimeSpan overflowed because the duration is too long. at System.TimeSpan.Interval(Double value, Int32 scale) at PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.GetTime(Single seconds) at PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.PaintInformation() at PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.GetSprites() at PowerGraph.Data.Scripts.PowerGraph.PowerChart.PaintInformationPanel() at PowerGraph.Data.Scripts.PowerGraph.PowerChart.Run() at Sandbox.Game.Entities.Blocks.MyTextPanelComponent.UpdateSpritesTexture() at Sandbox.Game.Entities.Blocks.MyTextPanel.UpdateAfterSimulation10()

Never seen this one before, but I'll do some research this Christmas.
Last edited by Skimt; 16 Dec, 2022 @ 3:13am
< >
Showing 1-4 of 4 comments
ArcWolf 29 Nov, 2022 @ 9:13pm 
Thread: 1 -> Exception occurred: System.OverflowException: TimeSpan overflowed because the duration is too long. at System.TimeSpan.Interval(Double value, Int32 scale) at PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.GetTime(Single seconds) at PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.PaintInformation() at PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.GetSprites() at PowerGraph.Data.Scripts.PowerGraph.PowerChart.PaintInformationPanel() at PowerGraph.Data.Scripts.PowerGraph.PowerChart.Run() at Sandbox.Game.Entities.Blocks.MyTextPanelComponent.UpdateSpritesTexture() at Sandbox.Game.Entities.Blocks.MyTextPanel.UpdateAfterSimulation10() at Sandbox.Game.Entities.MyParallelEntityUpdateOrchestrator.UpdateAfterSimulation10() at Sandbox.Game.Entities.MyParallelEntityUpdateOrchestrator.DispatchAfterSimulation() at Sandbox.Game.Entities.MyEntities.UpdateAfterSimulation() at Sandbox.Game.World.MySector.UpdateAfterSimulation() at Sandbox.Game.World.MySession.UpdateComponents() at Sandbox.Game.World.MySession.Update(MyTimeSpan updateTime) at Sandbox.MySandboxGame.Update() at Sandbox.Engine.Platform.Game.UpdateInternal() at Sandbox.Engine.Platform.Game.RunSingleFrame() at Sandbox.Engine.Platform.FixedLoop.<>c__DisplayClass11_0.<Run>b__0() at Sandbox.Engine.Platform.GenericLoop.Run(VoidAction tickCallback) at Sandbox.Engine.Platform.Game.RunLoop() at Sandbox.MySandboxGame.Run(Boolean customRenderLoop, Action disposeSplashScreen) at SpaceEngineers.MyProgram.Main(String[] args) 2022-11-25 17:54:40.044 - Thread: 1 -> Showing message

Thats the full crash log. The crash has happened to me 4 times now. It seems to occur when my Defense shield finishes charging. I have a base that was generating about 15Gw of power and also have a mod that provides capacitors so I can dump a large amount of power into my grid as a buffer for heavy load situations. About 2 or 3 Gw in maybe 30seconds or so. If I get into a scrap and take a large amount of shield damage the shields charge up using all the capacitors power then my guess is the caps fill up and because of how the game calculates the drain / charge time it overflows your scripts calculations. The capacitors are always floating at around 99% charge when idle.

Anyway, thats my best guess. About all that I can help on this error. Would love to continue to use this script. Up till this issue it was a staple of my builds. But right now, I've got it on ice till the CTD thing is resolved. :-/

Thanks for looking into it. Good luck ('-')7
Skimt  [developer] 30 Nov, 2022 @ 4:34pm 
Error location in TimeSpan.Interval() -> InformationPanel.GetTime() as seen below:

System.TimeSpan.Interval() PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.GetTime() PowerGraph.Data.Scripts.PowerGraph.Panels.InformationPanel.PaintInformation()

Googled: "System.OverflowException TimeSpan overflowed because the duration is too long" and received the following StackOverflow response by Juan Redondo (https://stackoverflow.com/a/60740007):

var variable1 = 1000; var variable2 = 0; TimeSpan.FromSeconds(variable1/variable2);

This will throw an "TimeSpan overflowed because the duration is too long." exception

Analysing error location in InformationPanel.GetTime():

InformationPanel.GetTime(float seconds) { // Error at line 112. TimeSpan batteryTime = TimeSpan.FromSeconds(seconds); }

Analysing error location in InformationPanel.PaintInformation():

InformationPanel.PaintInformation() { // Starts at 0, but shouldn't be a problem because it's the dividend. float fromCharge; // This is the divisor, and can thus cause a critical error. float charge = Math.Abs(powerMonitor.TotalStoring) * DT; // Line 93-94. Error probability at line 93. Error at line 94. float seconds = charge != 0 ? (fromCharge / charge) * 60f : 0; txtRemaining += GetTime(seconds); }

Upon analysis, the variable "charge" is checked for 0, but the whole algorithm in "seconds" is set to 0 if the "charge" variable is 0. This is a problem if TimeSpan.FromSeconds() cannot handle 0.

Possible solution #1:

InformationPanel.PaintInformation() { float seconds = charge != 0 ? (fromCharge / charge) * 60f : 1; // Set to 1. }

Possible solution #2:

InformationPanel.GetTime() { TimeSpan batteryTime = seconds != 0 ? TimeSpan.FromSeconds(seconds) : TimeSpan.MinValue; }

Solution #2 seems better, as seconds should be able to be 0. By using solution #1, seconds will never be below 1.
Last edited by Skimt; 18 Dec, 2022 @ 3:56am
Skimt  [developer] 30 Nov, 2022 @ 4:36pm 
I have a few more days of work at university. Will try to get this resolved before the holidays so that you can use the script again.

Thanks for quick and concise error report :steamthumbsup:
Skimt  [developer] 16 Dec, 2022 @ 3:13am 
Updated the mod using Solution #2.

Locking the thread until the issue arises again.
< >
Showing 1-4 of 4 comments
Per page: 1530 50