MaxMod2 crashing on channel destructor

BlitzMax Forums/BlitzMax Programming/MaxMod2 crashing on channel destructor

jtfrench(Posted 2010) [#1]
Hey folks,

I've run into a problem using MaxMod. I've been using it since 2008 when I first saw the .ogg streaming support. I've since updated my code to use MaxMod2 (which I believe switches the API to using calls like "PlayMusic" instead of "CreateAudioStream". For streaming .oggs, everything seems to work fine. I load a remote .ogg URL through LoadBank(), and pass that on to PlayMusic. Plays back fine, when the songs over, it stops fine.

However, when I play back a local .ogg (not through PlayMusic, but through PlaySound), it crashes after the sound is finished playing, sometime during garbage collection/memory cleanup in MaxModChannel. It looks like things crash when the MaxMod thread calls the destructor for Channels.

Any idea of what could be up? If you have any insight to share, it'd be greatly appreciated :) Thanks!


Here's my stack trace:
Process:         client.debug.mt [4279]
Path:            /Users/jfrench/Documents/Phoenix/client/client.debug.mt.app/Contents/MacOS/client.debug.mt
Identifier:      client.debug.mt
Version:         ??? (???)
Code Type:       X86 (Native)
Parent Process:  bmk [4270]

Interval Since Last Report:          51209 sec
Crashes Since Last Report:           4
Per-App Interval Since Last Report:  0 sec
Per-App Crashes Since Last Report:   3

Date/Time:       2010-12-05 05:55:39.644 -0800
OS Version:      Mac OS X 10.5.8 (9L31a)
Report Version:  6
Anonymous UUID:  4AB68451-ACAC-41F3-AA5F-77253DA7DD0C

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000c5c8d32b
Crashed Thread:  3

Thread 0:
0   com.apple.CoreFoundation      	0x90eebb39 CFDictionaryGetValue + 9
1   com.apple.CoreFoundation      	0x90f145b5 _CFRunLoop0 + 85
2   com.apple.CoreFoundation      	0x90f18a6f CFRunLoopRunSpecific + 751
3   com.apple.CoreFoundation      	0x90f19aa8 CFRunLoopRunInMode + 88
4   com.apple.HIToolbox           	0x928352ac RunCurrentEventLoopInMode + 283
5   com.apple.HIToolbox           	0x928350c5 ReceiveNextEventCommon + 374
6   com.apple.HIToolbox           	0x92834f39 BlockUntilNextEventMatchingListInMode + 106
7   com.apple.AppKit              	0x944e96d5 _DPSNextEvent + 657
8   com.apple.AppKit              	0x944e8f88 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
9   client.debug.mt               	0x00359646 updateEvents + 335
10  client.debug.mt               	0x00359803 bbSystemPoll + 29
11  client.debug.mt               	0x0035831d _brl_system_TMacOSSystemDriver_Poll + 51
12  client.debug.mt               	0x003577ba 70 + 8
13  client.debug.mt               	0x002ddf26 brl_polledinput_MouseX + 85
14  client.debug.mt               	0x00020174 _bb_RenderKit_mouseInRect + 112
15  client.debug.mt               	0x0000ec4e 11982 + 71
16  client.debug.mt               	0x0000e6b7 11892 + 8
17  client.debug.mt               	0x0001df54 15608 + 8
18  client.debug.mt               	0x00007af5 10311 + 8
19  client.debug.mt               	0x00003646 4 + 25
20  client.debug.mt               	0x00003951 run + 82
21  client.debug.mt               	0x00003b89 -[BlitzMaxAppDelegate applicationDidFinishLaunching:] + 353
22  com.apple.Foundation          	0x93fd342a _nsnote_callback + 106
23  com.apple.CoreFoundation      	0x90efa47a __CFXNotificationPost + 362
24  com.apple.CoreFoundation      	0x90efa753 _CFXNotificationPostNotification + 179
25  com.apple.Foundation          	0x93fd0680 -[NSNotificationCenter postNotificationName:object:userInfo:] + 128
26  com.apple.Foundation          	0x93fd9ed8 -[NSNotificationCenter postNotificationName:object:] + 56
27  com.apple.AppKit              	0x94572df2 -[NSApplication _postDidFinishNotification] + 125
28  com.apple.AppKit              	0x94572d01 -[NSApplication _sendFinishLaunchingNotification] + 77
29  com.apple.AppKit              	0x944ec81b -[NSApplication(NSAppleEventHandling) _handleAEOpen:] + 284
30  com.apple.AppKit              	0x944ec014 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 98
31  com.apple.Foundation          	0x93ff8a9f -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 655
32  com.apple.Foundation          	0x93ff87af _NSAppleEventManagerGenericHandler + 223
33  com.apple.AE                  	0x952e9648 aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned long, unsigned char*) + 144
34  com.apple.AE                  	0x952e957e dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 44
35  com.apple.AE                  	0x952e9425 aeProcessAppleEvent + 177
36  com.apple.HIToolbox           	0x92837981 AEProcessAppleEvent + 38
37  com.apple.AppKit              	0x944e98e9 _DPSNextEvent + 1189
38  com.apple.AppKit              	0x944e8f88 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
39  com.apple.AppKit              	0x944e1f9f -[NSApplication run] + 795
40  client.debug.mt               	0x00003dd5 main + 582
41  client.debug.mt               	0x00002f9b _start + 209
42  client.debug.mt               	0x00002ec9 start + 41

Thread 1:
0   libSystem.B.dylib             	0x90997266 mach_msg_trap + 10
1   libSystem.B.dylib             	0x9099ea5c mach_msg + 72
2   com.apple.CoreFoundation      	0x90f18e7e CFRunLoopRunSpecific + 1790
3   com.apple.CoreFoundation      	0x90f19aa8 CFRunLoopRunInMode + 88
4   com.apple.audio.CoreAudio     	0x9393b5f8 HALRunLoop::OwnThread(void*) + 160
5   com.apple.audio.CoreAudio     	0x9393b480 CAPThread::Entry(CAPThread*) + 96
6   libSystem.B.dylib             	0x909c8155 _pthread_start + 321
7   libSystem.B.dylib             	0x909c8012 thread_start + 34

Thread 2:
0   libSystem.B.dylib             	0x9099e44e __semwait_signal + 10
1   libSystem.B.dylib             	0x909c8dcd pthread_cond_wait$UNIX2003 + 73
2   libGLProgrammability.dylib    	0x91133b32 glvmDoWork + 162
3   libSystem.B.dylib             	0x909c8155 _pthread_start + 321
4   libSystem.B.dylib             	0x909c8012 thread_start + 34

Thread 3 Crashed:
0   client.debug.mt               	0x001b8adc IMaxModChannel::~IMaxModChannel() + 122
1   client.debug.mt               	0x001b8b22 MaxMod_ChannelFinished(IMaxModChannel const*) + 50
2   client.debug.mt               	0x001b9c3c void std::list<IMaxModChannel*, std::allocator<IMaxModChannel*> >::remove_if<bool (*)(IMaxModChannel const*)>(bool (*)(IMaxModChannel const*)) + 74
3   client.debug.mt               	0x001b93ed MaxMod_ProcessChannels(void*, unsigned int) + 89
4   client.debug.mt               	0x001b2dc4 RtCallback(void*, void*, unsigned int, double, unsigned int, void*) + 36
5   client.debug.mt               	0x001ab1f5 RtApiCore::callbackEvent(unsigned long, AudioBufferList const*, AudioBufferList const*) + 585
6   client.debug.mt               	0x001abb7c callbackHandler(unsigned long, AudioTimeStamp const*, AudioBufferList const*, AudioTimeStamp const*, AudioBufferList*, AudioTimeStamp const*, void*) + 52
7   com.apple.audio.CoreAudio     	0x9394d177 HP_IOProc::Call(AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioTimeStamp const&, AudioBufferList*) + 319
8   com.apple.audio.CoreAudio     	0x9394ce68 IOA_Device::CallIOProcs(AudioTimeStamp const&, AudioTimeStamp const&, AudioTimeStamp const&) + 274
9   com.apple.audio.CoreAudio     	0x9394cd44 HP_IOThread::PerformIO(AudioTimeStamp const&) + 1246
10  com.apple.audio.CoreAudio     	0x9394b11f HP_IOThread::WorkLoop() + 1239
11  com.apple.audio.CoreAudio     	0x9394ac43 HP_IOThread::ThreadEntry(HP_IOThread*) + 17
12  com.apple.audio.CoreAudio     	0x9393b480 CAPThread::Entry(CAPThread*) + 96
13  libSystem.B.dylib             	0x909c8155 _pthread_start + 321
14  libSystem.B.dylib             	0x909c8012 thread_start + 34

Thread 3 crashed with X86 Thread State (32-bit):
  eax: 0xc5c8d32b  ebx: 0x001b8a6e  ecx: 0x00000001  edx: 0x007cd000
  edi: 0x010f6a00  esi: 0x00000000  ebp: 0xb01c8978  esp: 0xb01c8950
   ss: 0x0000001f  efl: 0x00010286  eip: 0x001b8adc   cs: 0x00000017
   ds: 0x0000001f   es: 0x0000001f   fs: 0x0000001f   gs: 0x00000037
  cr2: 0xc5c8d32b



jtfrench(Posted 2010) [#2]
BlitzMax IDE's output is printing this at time of the crash:

MaxMod2: ~IMaxModSound
MaxMod2: ~IMaxModSound
client.debug.mt(4721,0xa008f720) malloc: *** error for object 0x17630010: Non-aligned pointer being freed (2)
*** set a breakpoint in malloc_error_break to debug
client.debug.mt(4721,0xa008f720) malloc: *** error for object 0x1bceb010: Non-aligned pointer being freed (2)
*** set a breakpoint in malloc_error_break to debug



jtfrench(Posted 2010) [#3]
The destructor (in C++) that its referring to, is this:

IMaxModChannel::~IMaxModChannel(){
//	mmPrint("~IMaxModChannel");
	delete AudioWrite_Mutex;
	delete RS;
	if(MUSIC) MUSIC->RemoveRef();
}



GfK(Posted 2010) [#4]
No idea what the problem is, however, the creator of MaxMod2 - REDi - hasn't been around here in a while and the MaxMod2 project on google is pretty much dead. On top of that, there are numerous issues being reported here (do a search) and no sign of them ever getting fixed.

I've used MaxMod for ages now but with all the problems cropping up on various systems, I'd strongly recommend not using it until there's some mention of whether or not it will ever be updated/stabilised.


jtfrench(Posted 2010) [#5]
Thanks for the advice, Gfk. What have you been using as an alternative? The main thing that brought me to MaxMod is the Ogg streaming support. It seems to be pretty good at that, though I'm interested in other options as well.

I think I figured out the bug. It looks like you have to explicitly make sure the channels don't get garbage collected or else when MaxMod references the pointer, it trips up. I've gotten around it now by just making sure not to gc it, but of course that won't work forever as that memory will need to be freed eventually. I'm still learning when is the right time to null the reference.


GfK(Posted 2010) [#6]
The only alternatives I know of would be BASS, IrrKlang or FMOD - none of which are free.

Going on from what I said before, I haven't been aware of a single complaint about audio in Magicville (which uses MaxMod2). But all of the reports about various issues have made me wonder if there could be memory leaks or other problems after long term use. Wish REDi was still about to look into it and have a tidy-up, or permit somebody else to take over the project.


jhans0n(Posted 2010) [#7]
Strictly speaking, nobody needs REDi's permission to take over the project. Anybody who wants to could branch it and pick up where he left off. The MIT license that is used on that module allows anyone to do whatever they want with the code. If someone does that, they would need to rename it since the MaxMod name wouldn't come along with the license.

I'd do it myself, but I barely have time for my own game projects so I'd be a poor choice to maintain it.


REDi(Posted 2010) [#8]
Hi jtfrench, could you supply some code that produces the crash, I've tried a couple of approaches and failed to replicate the problem so far.

I would suggest using SetAudioStreamDriver rather than SetAudioDriver, and use FreeAudio (or whatever) for sample playback until we get to the bottom of this.

Last edited 2010


REDi(Posted 2010) [#9]
LOL, just figured out why I can't replicate this bug, it turns out I fixed it ages ago and hadn't updated the download. F'in idiot :)

Will update soon, just going to look into a couple of other issues first.


xlsior(Posted 2010) [#10]
Hehehehe. Gotta love those. :-)


GfK(Posted 2010) [#11]
Pffft! :D