Skip to content

Commit

Permalink
Add exception handling to cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed May 3, 2023
1 parent 9359ed2 commit 0c6899f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions MechJeb2/MechJebLib/Core/ODE/AbstractIVP.cs
Expand Up @@ -77,9 +77,21 @@ public abstract class AbstractIVP
public void Solve(IVPFunc f, IReadOnlyList<double> y0, IList<double> yf, double t0, double tf, Hn? interpolant = null,
List<IVPEvent>? events = null)
{
N = y0.Count;
Initialize();
try
{
N = y0.Count;
Initialize();
_Solve(f, y0, yf, t0, tf, interpolant, events);
}
finally
{
Cleanup();
}
}

private void _Solve(IVPFunc f, IReadOnlyList<double> y0, IList<double> yf, double t0, double tf, Hn? interpolant,
List<IVPEvent>? events)
{
using var ynew = Vn.Rent(N);
using var dynew = Vn.Rent(N);
using var dy = Vn.Rent(N);
Expand Down Expand Up @@ -156,8 +168,6 @@ public abstract class AbstractIVP
interpolant?.Add(t, y, dy);

y.CopyTo(yf);

Cleanup();
}

protected abstract double Step(IVPFunc f, double t, double habs, int direction, Vn y, Vn dy, Vn ynew, Vn dynew);
Expand Down

0 comments on commit 0c6899f

Please sign in to comment.