Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions LSL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,16 @@ public double pull_sample(string[] sample, double timeout = LSL.FOREVER)
double res = dll.lsl_pull_sample_str(obj, tmp, tmp.Length, timeout, ref ec); LSL.check_error(ec);
try
{
for (int k = 0; k < tmp.Length; k++)
sample[k] = Marshal.PtrToStringAnsi(tmp[k]);
// liblsl >= 1.18 leaves tmp untouched (all null) when no sample was available (res == 0.0);
// in that case leave the caller's array untouched too, like the numeric overloads do.
if (res != 0.0)
for (int k = 0; k < tmp.Length; k++)
sample[k] = Marshal.PtrToStringAnsi(tmp[k]);
}
finally
{
// lsl_destroy_string is null-safe; always free so older liblsl versions
// (which allocate empty strings on timeout) don't leak.
for (int k = 0; k < tmp.Length; k++)
dll.lsl_destroy_string(tmp[k]);
}
Expand Down
Loading