I want an exception message but my threaded callback just dies or crashes

Markus fmmbj at protonmail.com
Wed Jun 12 11:32:39 UTC 2019


On Tuesday, 11 June 2019 at 05:15:17 UTC, Markus wrote:
> I have cleaned it up, kind of. Just in case you want to compile 
> it. The Zip contains some DLL from 
> https://github.com/spatialaudio/portaudio-binaries where you 
> can find the original if you want.
>
> https://gofile.io/?c=NpUxrJ
>
> I'm in general thinking of buying a Mac. I know it has not much 
> to do with this, but debugging Swift code in Xcode must be so 
> "gorgeous" as they say.

1) So, I've made it work. Using a global in the test.d for 
sharing between threads was no good idea it seems. It's just that 
I tend to do it because you will not end up passing arguments so 
much. But the shared keyword forced me to add D-atomic code, so I 
gave that up early and made it passing (borrowing?) the 
context/custom-data as argument, not being in global scope.

2) Second thing is, I removed collectException, because I was 
unable to do with it what it seems to be good for. I replaced it 
with another function call to a function that uses a try block, 
and assumeNoThrow goes around that function call.

I'm a bit confused but it works (can print Exceptions). :) The 
changes look like this:

test.d:

auto stream = start_portaudio(44100, 512, 
&on_audio_buffer,cast(void*)sine_sound);
// 1) pass around sine_sound, or anything that looks like a global

portaudio.d:

void on_audio_buffer_2(int frames, float* left, float* right, 
paTestData* data)
{
	// 2)
	try
	{
		data.callback(
			data.frames_per_buffer,
			&data.left_buf[0],
			&data.right_buf[0],
			data.mydata);		
	}
	catch(Throwable e)
	{
		writefln("e==%s",e.toString);
		TerminateProcess(GetCurrentProcess(), 0);		
	}
}

extern(C) nothrow int patestCallback(........)
{
	// 2) call the function that uses the try block
	assumeWontThrow(
			on_audio_buffer_2(
			data.frames_per_buffer,
			&data.left_buf[0],
			&data.right_buf[0],
			data));
}


More information about the Digitalmars-d-learn mailing list