I want an exception message but my threaded callback just dies or crashes
Markus
fmmbj at protonmail.com
Tue Jun 11 04:48:48 UTC 2019
Hi, when you use core.windows and LoadLibrary to load a DLL, and
that DLL will create a new thread and inside that it will call
back into your D app, is there something to special to be aware
of?
I've done it like with the CreateWindow and WndProc, but this
time I'm loading a compiled portaudio DLL and I give it a call
back. And I try to catch errors, but no matter what D Exception
(I tried out of range and null dereferencing) that thread seems
to either die silently (no hints in my console) or somehow fail
to make portaudio go on calling (I don't think so).
I just wanted to ask if you know any pitfall with this... I'll go
on using windbg and looking at things. I guess I should post a
complete project, but I have to clean it up, and you maybe don't
want to execute that portaudio32bit.dll from some unknown github
account.
The function for Portaudio looks like that:
extern(C) nothrow int patestCallback(
const void* inputBuffer,
void* outputBuffer,
uint framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void* userData)
{
auto data = cast(paTestData*)userData;
auto out_ = cast(float*)outputBuffer;
auto ce = collectException(
data.callback(
data.frames_per_buffer,
&data.left_buf[0],
&data.right_buf[0]));
if(ce !is null)
{
assumeWontThrow(writeln(ce.toString));
TerminateProcess(GetCurrentProcess(), 0);
} else
{
assumeWontThrow(writeln("ce is null"));
}
for(uint i = 0; i < framesPerBuffer; ++i)
{
*out_++ = data.left_buf[i];
*out_++ = data.right_buf[i];
}
return PaStreamCallbackResult.paContinue;
}
...
...
I give it to Portaudio like that
{ auto err = Pa_OpenStream(
&stream,
null,
&outputParameters,
frames_per_second,
frames_per_buffer,
paClipOff,
&patestCallback,
&data);
More information about the Digitalmars-d-learn
mailing list