I'm currently writing some Dart bindings for a library written in C++. I am trying to bind a function defined as follows:
SYZ_CAPI syz_ErrorCode syz_echoSetTaps(syz_Handle handle, unsigned int n_taps, struct syz_EchoTapConfig *taps);
Far as I can tell, `taps` is supposed to be an array of ` syz_EchoTapConfig` structs.
Here is my function (it's mercifully short):
/// Sets the taps of the echo.
void setTaps(List<EchoTapConfig>? taps) {
if (taps == null || taps.isEmpty) {
synthizer
.check(synthizer.synthizer.syz_echoSetTaps(handle.value, 0, nullptr));
} else {
final a = Array<Pointer<syz_EchoTapConfig>>(taps.length);
for (var i = 0; i < taps.length; i++) {
final t = taps[i];
final tc = calloc<syz_EchoTapConfig>();
tc.ref
..delay = t.delay
..gain_l = t.gainL
..gain_r = t.gainR;
a[i] = tc; // This line causes a crash.
print(a);
}
synthizer.check(
synthizer.synthizer.syz_echoSetTaps(handle.value, taps.length, a[0]));
}
}
I'm reasonably sure my problem lies with my use of the Array class, and (more specifically), then StructArray extension, which gives it the [] operator.
Can anyone suggest what I can do next? I have tried googling, but I can't find aexamples of using the Array class, neither in the examples for dart:ffi, or the ffi package.
If you need more info, please tell me. I'm by no means a C++ programmer, and I'm not really sure what info to provide to be useful rather than extraneously verbose.