Back to the Vavoom Forum Archives


Forum

Crash when using Timidity as music

Mon, 22 Mar 2010 00:30:15

Firebrand

I'm getting a strange crash when using Timidity as music device, the game starts having music normally, but when starting the game I get the following:
- VTimidityAudioCodec::Create
- VAudio::PlaySong
- VAudio::CmdMusic
- COMMAND Music
- VCommand::ExecuteString
- VCmdBuf::Exec
- Host_Frame
Log: Doing C_Shutdown
Log: Doing CL_Shutdown
Log: PLAYER left the game

Log: Doing SV_Shutdown
Log: Doing delete GNet
Log: Doing delete GInput
Log: Doing V_Shutdown
Log: Doing delete GAudio
Log: Doing T_Shutdown
Log: Doing Sys_Shutdown
Log: Doing delete GSoundManager
Log: Doing R_ShutdownTexture
Log: Doing R_ShutdownData
Log: Doing VCommand::Shutdown
Log: Doing VCvar::Shutdown
Log: Doing ShutdownMapInfo
Log: Doing FL_Shutdown
Log: Doing W_Shutdown
Log: Doing GLanguage.FreeData
Log: Doing ShutdownDecorate
Log: Doing VObject::StaticExit
Log: Doing VName::StaticExit
Uninitialised: Doing Z_Shutdown


ERROR: Segmentation Violation
I'm using eawpats that I downloaded from here: [url:2u7250st]http://www.doomworld.com/idgames/index.php?id=13928 Maybe the config file has some parameters that aren't implemented yet?
Mon, 22 Mar 2010 23:01:47

Janis Legzdinsh

I tried them and they worked fine for me. Can you try to debug it in Visual Studio?
Mon, 22 Mar 2010 23:42:52

Firebrand

OK, I've got the debugging results, it seems like there's some kind of memory leak when loading the config files, here's the call stack:
>	vavoom.exe!LibTimidity::read_config_file(const char * name=0x0012f3e3)  Line 284 + 0x11 bytes	C++
 	vavoom.exe!LibTimidity::read_config_file(const char * name=0x00710ef8)  Line 192 + 0x13 bytes	C++
 	vavoom.exe!LibTimidity::Timidity_Init()  Line 420 + 0xa bytes	C++
 	vavoom.exe!VTimidityAudioCodec::Create(VStream * InStrm=0x046dbb3c)  Line 209 + 0x5 bytes	C++
 	vavoom.exe!VAudio::PlaySong(const char * Song=0x01b37ed4, bool Loop=true)  Line 1280 + 0xf bytes	C++
 	vavoom.exe!VAudio::CmdMusic(const TArray<VStr> & Args={...})  Line 1380	C++
 	vavoom.exe!TCmdMusic::Run()  Line 2062	C++
 	vavoom.exe!VCommand::ExecuteString(const VStr & Acmd={...}, VCommand::ECmdSource src=SRC_Command, VBasePlayer * APlayer=0x00000000)  Line 415	C++
 	vavoom.exe!VCmdBuf::Exec()  Line 601 + 0xd bytes	C++
 	vavoom.exe!Host_Frame()  Line 352	C++
 	vavoom.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * __formal=0x00000000, HINSTANCE__ * __formal=0x00000000, int iCmdShow=10)  Line 672	C++
 	vavoom.exe!__tmainCRTStartup()  Line 263 + 0x2c bytes	C
 	vavoom.exe!WinMainCRTStartup()  Line 182	C
 	kernel32.dll!775b1194() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
 	ntdll.dll!7769b3f5() 	
 	ntdll.dll!7769b3c8() 	
 	vavoom.exe!LibTimidity::ReadImod(LibTimidity::Sf2Data * font=0x01190304, LibTimidity::RIFF_Chunk * chunk=0x01070107)  Line 546 + 0x10 bytes	C++
 	02080108()	
I'm attaching a print screen of the debugging session here too.
Tue, 23 Mar 2010 22:50:29

Firebrand

I've found that the bank->tone becomes corrupted or is pointing to a NULL place, but I don't know how it can happen since it seems to be filling the tone banks correctly... I'll keep investigating the cause of the problem.
Tue, 13 Apr 2010 21:18:58

Firebrand

Apparently, the problem was a memory leak, the free method doesn't NULL the pointers properly, causing indefinite behavior, I've fixed most of the calls to the free method on all the timidity library and it seems to work properly now, here's the diff patch, let me know what you think of it.
Index: source/timidity/instrum.cpp
===================================================================
--- source/timidity/instrum.cpp	(revision 4217)
+++ source/timidity/instrum.cpp	(working copy)
@@ -53,10 +53,13 @@
 		if (sp->data)
 		{
 			free(sp->data);
+			sp->data = NULL;
 		}
 	}
 	free(ip->sample);
+	ip->sample = NULL;
 	free(ip);
+	ip = NULL;
 }
 
 static void free_bank(MidiSong* song, int dr, int b)
@@ -406,6 +409,7 @@
 			cp = (uint8*)(sp->data);
 			sp->data = (sample_t*)newdta;
 			free(cp);
+			cp = NULL;
 			sp->data_length *= 2;
 			sp->loop_start *= 2;
 			sp->loop_end *= 2;
Index: source/timidity/instrum_dls.cpp
===================================================================
--- source/timidity/instrum_dls.cpp	(revision 4217)
+++ source/timidity/instrum_dls.cpp	(working copy)
@@ -78,6 +78,7 @@
 		FreeRIFFChunk(chunk->next);
 	}
 	free(chunk);
+	chunk = NULL;
 }
 
 static int ChunkHasSubType(uint32 magic)
@@ -211,6 +212,7 @@
 void FreeRIFF(RIFF_Chunk *chunk)
 {
 	free(chunk->data);
+	chunk->data = NULL;
 	FreeRIFFChunk(chunk);
 }
 
@@ -327,6 +329,7 @@
 {
 	if ( instrument->regions ) {
 		free(instrument->regions);
+		instrument->regions = NULL;
 	}
 }
 
@@ -348,6 +351,7 @@
 			FreeRegions(&data->instruments);
 		}
 		free(data->instruments);
+		data->instruments = NULL;
 	}
 }
 
@@ -365,6 +369,7 @@
 {
 	if ( data->waveList ) {
 		free(data->waveList);
+		data->waveList = NULL;
 	}
 }
 
@@ -719,6 +724,7 @@
 	FreeInstruments(data);
 	FreeWaveList(data);
 	free(data);
+	data = NULL;
 }
 
 /*-------------------------------------------------------------------------*/
Index: source/timidity/instrum_sf2.cpp
===================================================================
--- source/timidity/instrum_sf2.cpp	(revision 4217)
+++ source/timidity/instrum_sf2.cpp	(working copy)
@@ -173,6 +173,7 @@
 		FreeRIFF(font->Riff);
 	}
 	free(font);
+	font = NULL;
 }
 
 //==========================================================================
Index: source/timidity/playmidi.cpp
===================================================================
--- source/timidity/playmidi.cpp	(revision 4217)
+++ source/timidity/playmidi.cpp	(working copy)
@@ -721,6 +721,7 @@
 	if (!song->events)
 	{
 		free(song);
+		song = NULL;
 		return NULL;
 	}
 
@@ -759,15 +760,25 @@
 	for (int i = 0; i < 128; i++)
 	{
 		if (song->tonebank)
+		{
 			free(song->tonebank);
+			song->tonebank = NULL;
+		}
 		if (song->drumset)
+		{
 			free(song->drumset);
+			song->drumset = NULL;
+		}
 	}
 
 	free(song->events);
+	song->events = NULL;
 	free(song->resample_buffer);
+	song->resample_buffer = NULL;
 	free(song->common_buffer);
+	song->common_buffer = NULL;
 	free(song);
+	song = NULL;
 }
 
 void Timidity_Close()
@@ -782,11 +793,16 @@
 				for (int j = 0; j < 128; j++)
 				{
 					if (e[j].name != NULL)
+					{
 						free(e[j].name);
+						e[j].name = NULL;
+					}
 				}
 				free(e);
+				e = NULL;
 			}
 			free(master_tonebank);
+			master_tonebank = NULL;
 		}
 		if (master_drumset)
 		{
@@ -796,11 +812,16 @@
 				for (int j = 0; j < 128; j++)
 				{
 					if (e[j].name != NULL)
+					{
 						free(e[j].name);
+						e[j].name = NULL;
+					}
 				}
 				free(e);
+				e = NULL;
 			}
 			free(master_drumset);
+			master_drumset = NULL;
 		}
 	}
 
Index: source/timidity/readmidi.cpp
===================================================================
--- source/timidity/readmidi.cpp	(revision 4217)
+++ source/timidity/readmidi.cpp	(working copy)
@@ -83,6 +83,7 @@
 	if (len != (int32)midi_read(song, s, len))
 	{
 		free(s);
+		s = NULL;
 		return -1;
 	}
 	s[len] = '\0';
@@ -93,6 +94,7 @@
 	}
 	ctl->cmsg(CMSG_TEXT, VERB_VERBOSE, "%s%s", label, s);
 	free(s);
+	s = NULL;
 	return 0;
 }
 
Index: source/timidity/timidity.cpp
===================================================================
--- source/timidity/timidity.cpp	(revision 4217)
+++ source/timidity/timidity.cpp	(working copy)
@@ -282,7 +282,10 @@
 				return -2;
 			}
 			if (bank->tone.name)
+			{
 				free(bank->tone.name);
+				bank->tone.name = NULL;
+			}
 			strcpy((bank->tone.name = (char*)safe_malloc(strlen(w[1]) + 1)), w[1]);
 			bank->tone.note = bank->tone.amp = bank->tone.pan =
 				bank->tone.strip_loop = bank->tone.strip_envelope =

Back to the Vavoom Forum Archives