no speakers = crash

BlitzMax Forums/BlitzMax Programming/no speakers = crash

GfK(Posted 2013) [#1]
Just got report of this happening. Its the old c++ runtime unusual termination error.

Works fine with speakers plugged in. Unplug them and the game falls over.

A bit vague I know but im on my phone and havent started to look at it yet.

Anybody heard of this before?


Brucey(Posted 2013) [#2]
Presumably the OS detects it and changes the current audio output to use a different driver/hardware.

Maybe the BlitzMax audio driver isn't handling the change very well. (although I'm not sure it should have to... you'd think the OS would deal with all of that)


GfK(Posted 2013) [#3]
Update: I've just checked the DXDiag logs, and the system with no speakers in, is showing there is no actual soundcard present. I'm sure that's cropped up before...


Brucey(Posted 2013) [#4]
Ah, so USB speakers?


GfK(Posted 2013) [#5]
That may be the case. But I've tracked the problem down, and it's...


*drumroll*


MAXMOD2! AGAIN!!

It fails if there is no soundcard present, whereas regular Blitzmax audio *silently* (sic) fails, i.e. without throwing a massive error.

Seriously - this thing is becoming a curse and it's getting to the point where I might pay somebody to provide an alternative that's less of a pain in the ass.

Need to find a way around this now...


GfK(Posted 2013) [#6]
Fix0r3d!

If SetAudioDriver("DirectSound")
	SetAudioStreamDriver("MaxMod RTAudio")
EndIf



therevills(Posted 2013) [#7]
Hey Dave... why do you use MaxMod in the first place?


GfK(Posted 2013) [#8]
Streaming audio. No other reason.

Seems this is only a partial fix - pulling the speaker plug out AFTER the game has started, results in the same crash...

(Again, this only affects MaxMod2 - regular Blitzmax audio takes care of itself).

[edit] I think it's time to bin MaxMod2. What are you using for music? LoadSound is taking 1500ms to load/decompress a music file (during which everything pauses), which is not really acceptable.


*(Posted 2013) [#9]
why not have a traditional loading screen :)


GfK(Posted 2013) [#10]
Well, something is definitely wrong. I'm testing some native audio stuff and have hit a new (but related) problem.

If I start the game with speakers plugged in, all good. If I then unplug the speakers (with the game still running), the next time I try to play a sound, be it via PlaySound, or CueSound, I get the following error:

DirectSound failed (150)


I speed-tested setting the audiodriver before every PlaySound, but each call takes around 8ms, which is unacceptably slow.

A bit stuck now...


GfK(Posted 2013) [#11]
Seem to have solved it for now, thus:
		Try
			Local c:TChannel = AllocChannel()
			CueSound(snd, c)
			c.SetPaused(False)
		Catch A:String
			'nowt - we should only go here if some muppet has ragged the speakers out mid-game.
		EndTry



GfK(Posted 2013) [#12]
...except that doesn't work so great either. Because in the case of game music, I am seemingly unable to stop any music that's already playing, should the speakers be removed mid-game.

This is a massive problem if the speakers are removed, then reattached, and somewhere between the two, the player has clicked into another area of the game which should have different music playing.

I need to punch something. :/


therevills(Posted 2013) [#13]
What are you using for music?

LoadSound... each screen has a load method which displays a "Loading" text/image if needed.


GfK(Posted 2013) [#14]
I stuck with MaxMod2 for now, but I just don't set the MaxMod RTAudio Driver (for streaming audio) if the DirectSound driver fails to initialise, and grey out the in-game audio/volume controls. This way, it starts up and runs fine whether there are speakers present or not.

If the DS driver starts up OK, then the speakers get unplugged, it will still crash with "DirectSound failed (150)" - even without MaxMod2 involved. I tried the same with FreeAudio and got a warning in the debug window, and all audio just died but the game continued running. With all of that said, I've sold thousands upon thousands of games and the issue of somebody unplugging their speakers causing a mid-game crash has never come up, not even once. So that's probably going to be a non-issue.

I'm still considering alternatives, though. Possibly irrKlang, as it's got plenty of features and decent price tag at ~£250.


Kryzon(Posted 2013) [#15]
Do you sell your games for less than £18? if so, you can get the irrKlang Pro Hobbyist which is just £57 (and has all features).

http://www.ambiera.com/irrklang/irrklang_pro.html


Brucey(Posted 2013) [#16]
The paid-for version is also static linkable, which means there's no unsightly extra dll to ship.

Let me know if you need a hand getting it working with the static library.


GfK(Posted 2013) [#17]
Do you sell your games for less than £18? if so, you can get the irrKlang Pro Hobbyist which is just £57 (and has all features).
I'm not an individual tho, I have a limited company now.

@Brucey: cheers for that!


BlitzSupport(Posted 2013) [#18]
Might be worth having a look at DSASS () in BlitzMax\mod\brl.mod\directsoundaudio.mod\directsoundaudio.bmx:

Function DSASS( n,t$="DirectSound" )
	If n>=0 Return
	Throw t+" failed ("+(n & 65535)+")"
End Function


Maybe see what happens without the Throw, which I assume is causing the exit after generating the message you're seeing? Or maybe try setting the sound driver to null there -- SetAudioDriver "Null"? Probably too late by that point, but I've no way to test this myself!


GfK(Posted 2013) [#19]
Interesting. I'll have a go at that tomorrow.


Russell(Posted 2013) [#20]
Just had a look at the IrrKlang website ( http://www.ambiera.com/irrklang/downloads.html ) and, concerning compiling with GCC 4.7+ they say:

The GCC developers made newer versions of gcc incompatible, so if you are using this new gcc version, download these irrklang binaries which will work with gcc 4.7 and newer


Seems the GCC people have caused a lot of problems with the changes they made... Whatever happened to backwards compatibility? What is it, exactly, that they're changing that's causing these issues? C++ is C++, right?

The gcc.gnu.org website ( http://gcc.gnu.org/gcc-4.7/cxx0x_status.html ) flatly proclaims:

...No attempts will be made to preserve backward compatibility with C++11 features whose semantics have changed during the course of C++11 standardization.


Well, isn't THAT special... So C++ itself is apparently undergoing some standardization changes (to make it even MORE cryptic in its syntax, no doubt!). Great.

Short of rewriting maxmod2 (or any other program(s) that are no longer compilable under GCC 4.7+), what can be done to make it/them work? Brucey?

Russell


Derron(Posted 2013) [#21]
A rewrite would be nice - but I think most of us use maxmod just for streaming purposes.

And no - not every game is having "screens" or "levels". I have eg. a game in which you can move through a building - each room you enter may have a different music and/or sound effects. If I preloaded ALL music files (users could add custom ones) I would end up preloading many megabytes of compressed audio into RAM (currently 50mb compressed, but like said: moddable).

I also have had to "mod" maxmod to get it working flawlessly on pulseaudio-driven linux DE. Why? If there is already a active sound output the app would stay silent. So I had to change the order of "driver recognition"...now I can play some music and start my app afterwards without stopping sound effects to work.

So instead of "dumb/flac..."-support I just would be in need of a decent, reliable player for streamed ogg/mp3. Of course it should allow multiple streams to play simultaneously (do not know the correct term for it at the moment - multichannel is something different I think).

bye
Ron


GfK(Posted 2013) [#22]
A rewrite would be nice - but I think most of us use maxmod just for streaming purposes
That's all I use it for, which does make the likes of BASS, FMOD, IrrKlang et al seem a little "overkill" for what I want to do.


Russell(Posted 2013) [#23]
I had a good look at BASS, FMOD and IrrKlang and I think IrrKlang is the most realistic payment scheme for me. Sure, all three are free for non-commercial use, but if you then decide to release your game as a shareware the price points change quite a bit. IrrKlang works out to about $85US [as of 2013 June 4th] for unlimited platforms per title, BASS is a bit more (about $163 - But PER platform) and FMOD is a LOT more ($500 PER platform - If your budget is less than $100K... Otherwise, it could be $15,000 or more!).

The only semi-major downside I could see for the IrrKlang library is, according to the website, static linking is only available on the Windows version (Why? Who knows?) and sound effects like echo and reverb, etc are only available on DirectSound (Windows). For me, these are not deal breakers because I can just include the DLL in the distribution and I don't generally need to change echo or reverb effects 'on-the-fly', so they can be generated when the sounds are encoded (using Audiere or whatever).

So, given that MaxMod2 does not appear to work with 4.7+, I'm going to switch to IrrKlang. It also has the benefit of being commercially supported.

Russell

p.s. If you need plugin support and/or lots of effects capabilities, then maybe BASS or FMOD are for you. You'll have to weigh that decision yourself.