Black Magic Programming

Sometimes you get to write code that just doesn’t make any sense at all. Like this:

// BLACK MAGIC: persuade mono not to crash
var x = Bass.BASS_GetVersion().ToString();

Of course, the variable x will neither be used nor touched anywhere else in code and the whole thing seems rather questionable. But:

Removing it, or placing it elsewhere in the code will reliably make the application crash with an obscure segfault in mono 3.2.3 on ARM Linux – The jargon file’s Story About Magic comes to mind.

Also, presumably the crash happens due to unspecified native library load order differences between .NET and mono – This certainly appears to be the case, from what we gathered by investigating with gdb. But why? I don’t know, and the folks at #mono@irc.gnome.org appear not to, either.

Oh well.  “We don’t know why we have to do this, but it works.” – All hail the art of Black Magic computer programming! My thanks go to the great master of sorcery, Ian Luck of un4seen.com fame, and to Shana and ShawnWhite from #raspberrypi@irc.freenode.net for helping me devise this great spell of protection, which essentially ensures that libbass.so is loaded when we access libbassmix.so – even under mono.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s