diff --git a/LSL.cs b/LSL.cs index bb7137d..6dfc17a 100644 --- a/LSL.cs +++ b/LSL.cs @@ -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]); }