Skip to content

Commit 793f149

Browse files
committed
Prevent crashes when debugger is visualizing a status and we dispose it
1 parent 6ba299e commit 793f149

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

TensorFlowSharp/Tensorflow.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ public void SetStatusCode (TFCode code, string msg)
279279
/// <value>The status code as an enumeration.</value>
280280
public TFCode StatusCode {
281281
get {
282+
if (handle == IntPtr.Zero)
283+
throw new ObjectDisposedException ("TFStatus");
282284
return TF_GetCode (handle);
283285
}
284286
}
@@ -299,6 +301,9 @@ public TFCode StatusCode {
299301
/// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:TensorFlow.TFStatus"/>.</returns>
300302
public override string ToString ()
301303
{
304+
if (handle == IntPtr.Zero)
305+
throw new ObjectDisposedException ("TFStatus");
306+
302307
return string.Format ("[TFStatus: StatusCode={0}, StatusMessage={1}]", StatusCode, StatusMessage);
303308
}
304309

@@ -342,7 +347,8 @@ internal bool CheckMaybeRaise (TFStatus incomingStatus, bool last = true)
342347
Console.WriteLine ("oops");
343348
if (StatusCode != TFCode.Ok) {
344349
var e = new TFException (StatusMessage);
345-
Dispose ();
350+
if (last)
351+
Dispose ();
346352
throw e;
347353
}
348354
if (last)

0 commit comments

Comments
 (0)