Skip to content

Commit bccd47d

Browse files
authored
refactor: return null if the output packet is empty (#1116)
1 parent 4615472 commit bccd47d

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

Assets/MediaPipeUnity/Samples/Common/Scripts/GraphRunner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ protected void AssertResult(params OutputStream.NextResult[] results)
214214

215215
protected bool TryGetValue<T>(Packet packet, out T value, Func<Packet, T> getter)
216216
{
217-
if (packet == null || packet.IsEmpty())
217+
if (packet == null)
218218
{
219219
value = default;
220220
return false;

Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/OutputStream.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public readonly struct OutputEventArgs
2626
{
2727
/// <summary>
2828
/// <see cref="Packet"/> that contains the output value.
29-
/// <see langword="null"/> if there's no output.
29+
/// As long as it's not <see langword="null"/>, it's guaranteed that <see cref="Packet.IsEmpty"/> is <see langword="false"/>.
3030
/// </summary>
3131
public readonly Packet packet;
3232
public readonly long timestampMicrosecond;
@@ -40,6 +40,10 @@ internal OutputEventArgs(Packet packet, long timestampMicrosecond)
4040

4141
public readonly struct NextResult
4242
{
43+
/// <summary>
44+
/// <see cref="Packet"/> that contains the output value.
45+
/// As long as it's not <see langword="null"/>, it's guaranteed that <see cref="Packet.IsEmpty"/> is <see langword="false"/>.
46+
/// </summary>
4347
public readonly Packet packet;
4448
/// <summary>
4549
/// <see langword="true"/> if the next packet is retrieved successfully; otherwise <see langword="false"/>.
@@ -343,6 +347,10 @@ private Task<NextResult> StartWaitNextTask()
343347
var stream = (OutputStream)state;
344348
if (stream.Next(out var packet)) // this blocks the thread
345349
{
350+
if (packet.IsEmpty())
351+
{
352+
return new NextResult(null, true);
353+
}
346354
return new NextResult(packet, true);
347355
}
348356
return new NextResult(null, false);

0 commit comments

Comments
 (0)