[quake3-commits] r2042 - in trunk/code: client null qcommon

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Jun 17 19:29:19 EDT 2011


Author: thilo
Date: 2011-06-17 19:29:19 -0400 (Fri, 17 Jun 2011)
New Revision: 2042

Modified:
   trunk/code/client/cl_main.c
   trunk/code/client/snd_codec_ogg.c
   trunk/code/client/snd_codec_wav.c
   trunk/code/client/snd_dma.c
   trunk/code/client/snd_local.h
   trunk/code/client/snd_mem.c
   trunk/code/client/snd_openal.c
   trunk/code/null/null_client.c
   trunk/code/qcommon/common.c
   trunk/code/qcommon/qcommon.h
Log:
- Fix memory leak in DMA sound after S_Shutdown()
- Make codec load use temp hunk memory instead of zone mem
- Fix sound issues with direct sound and game_restart (#4526)

Modified: trunk/code/client/cl_main.c
===================================================================
--- trunk/code/client/cl_main.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/client/cl_main.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -1776,10 +1776,10 @@
 Restart the sound subsystem
 =================
 */
-void CL_Snd_Restart(void)
+void CL_Snd_Shutdown(void)
 {
 	S_Shutdown();
-	S_Init();
+	cls.soundStarted = qfalse;
 }
 
 /*
@@ -1793,7 +1793,8 @@
 */
 void CL_Snd_Restart_f(void)
 {
-	CL_Snd_Restart();
+	CL_Snd_Shutdown();
+	// sound will be reinitialized by vid_restart
 	CL_Vid_Restart_f();
 }
 
@@ -3350,7 +3351,7 @@
 
 	CL_Disconnect( qtrue );
 
-	S_Shutdown();
+	CL_Snd_Shutdown();
 	CL_ShutdownRef();
 	
 	CL_ShutdownUI();

Modified: trunk/code/client/snd_codec_ogg.c
===================================================================
--- trunk/code/client/snd_codec_ogg.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/client/snd_codec_ogg.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -450,7 +450,7 @@
 
 	// allocate a buffer
 	// this buffer must be free-ed by the caller of this function
-    	buffer = Z_Malloc(info->size);
+    	buffer = Hunk_AllocateTempMemory(info->size);
 	if(!buffer)
 	{
 		S_OGG_CodecCloseStream(stream);
@@ -464,7 +464,7 @@
 	// we don't even have read a single byte
 	if(bytesRead <= 0)
 	{
-		Z_Free(buffer);
+		Hunk_FreeTempMemory(buffer);
 		S_OGG_CodecCloseStream(stream);
 
 		return NULL;	

Modified: trunk/code/client/snd_codec_wav.c
===================================================================
--- trunk/code/client/snd_codec_wav.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/client/snd_codec_wav.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -218,7 +218,7 @@
 	}
 
 	// Allocate some memory
-	buffer = Z_Malloc(info->size);
+	buffer = Hunk_AllocateTempMemory(info->size);
 	if(!buffer)
 	{
 		FS_FCloseFile(file);

Modified: trunk/code/client/snd_dma.c
===================================================================
--- trunk/code/client/snd_dma.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/client/snd_dma.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -391,9 +391,8 @@
 	if (s_numSfx == 0) {
 		SND_setup();
 
-		s_numSfx = 0;
-		Com_Memset( s_knownSfx, 0, sizeof( s_knownSfx ) );
-		Com_Memset(sfxHash, 0, sizeof(sfx_t *)*LOOP_HASH);
+		Com_Memset(s_knownSfx, '\0', sizeof(s_knownSfx));
+		Com_Memset(sfxHash, '\0', sizeof(sfx_t *) * LOOP_HASH);
 
 		S_Base_RegisterSound("sound/feedback/hit.wav", qfalse);		// changed to a sound in baseq3
 	}
@@ -1467,8 +1466,10 @@
 	}
 
 	SNDDMA_Shutdown();
+	SND_shutdown();
 
 	s_soundStarted = 0;
+	s_numSfx = 0;
 
 	Cmd_RemoveCommand("s_info");
 }

Modified: trunk/code/client/snd_local.h
===================================================================
--- trunk/code/client/snd_local.h	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/client/snd_local.h	2011-06-17 23:29:19 UTC (rev 2042)
@@ -202,6 +202,7 @@
 void		SND_free(sndBuffer *v);
 sndBuffer*	SND_malloc( void );
 void		SND_setup( void );
+void		SND_shutdown(void);
 
 void S_PaintChannels(int endtime);
 

Modified: trunk/code/client/snd_mem.c
===================================================================
--- trunk/code/client/snd_mem.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/client/snd_mem.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -100,6 +100,12 @@
 	Com_Printf("Sound memory manager started\n");
 }
 
+void SND_shutdown(void)
+{
+		free(sfxScratchBuffer);
+		free(buffer);
+}
+
 /*
 ================
 ResampleSfx
@@ -255,7 +261,7 @@
 	}
 	
 	Hunk_FreeTempMemory(samples);
-	Z_Free(data);
+	Hunk_FreeTempMemory(data);
 
 	return qtrue;
 }

Modified: trunk/code/client/snd_openal.c
===================================================================
--- trunk/code/client/snd_openal.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/client/snd_openal.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -148,7 +148,7 @@
 // Sound effect storage, data structures
 #define MAX_SFX 4096
 static alSfx_t knownSfx[MAX_SFX];
-static int numSfx = 0;
+static sfxHandle_t numSfx = 0;
 
 static sfxHandle_t default_sfx;
 
@@ -332,7 +332,7 @@
 	if (!cache)
 	{
 		// Don't create AL cache
-		Z_Free(data);
+		Hunk_FreeTempMemory(data);
 		return;
 	}
 
@@ -344,7 +344,7 @@
 	if((error = qalGetError()) != AL_NO_ERROR)
 	{
 		S_AL_BufferUseDefault(sfx);
-		Z_Free(data);
+		Hunk_FreeTempMemory(data);
 		Com_Printf( S_COLOR_RED "ERROR: Can't create a sound buffer for %s - %s\n",
 				curSfx->filename, S_AL_ErrorMsg(error));
 		return;
@@ -369,7 +369,7 @@
 		if( !S_AL_BufferEvict( ) )
 		{
 			S_AL_BufferUseDefault(sfx);
-			Z_Free(data);
+			Hunk_FreeTempMemory(data);
 			Com_Printf( S_COLOR_RED "ERROR: Out of memory loading %s\n", curSfx->filename);
 			return;
 		}
@@ -383,7 +383,7 @@
 	if(error != AL_NO_ERROR)
 	{
 		S_AL_BufferUseDefault(sfx);
-		Z_Free(data);
+		Hunk_FreeTempMemory(data);
 		Com_Printf( S_COLOR_RED "ERROR: Can't fill sound buffer for %s - %s\n",
 				curSfx->filename, S_AL_ErrorMsg(error));
 		return;
@@ -392,7 +392,7 @@
 	curSfx->info = info;
 	
 	// Free the memory
-	Z_Free(data);
+	Hunk_FreeTempMemory(data);
 
 	// Woo!
 	curSfx->inMemory = qtrue;
@@ -460,7 +460,7 @@
 		S_AL_BufferUnload(i);
 
 	// Clear the tables
-	memset(knownSfx, 0, sizeof(knownSfx));
+	numSfx = 0;
 
 	// All undone
 	alBuffersInitialised = qfalse;
@@ -2205,6 +2205,8 @@
 static
 void S_AL_BeginRegistration( void )
 {
+	if(!numSfx)
+		S_AL_BufferInit();
 }
 
 /*

Modified: trunk/code/null/null_client.c
===================================================================
--- trunk/code/null/null_client.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/null/null_client.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -85,7 +85,7 @@
 void CL_StartHunkUsers( qboolean rendererOnly ) {
 }
 
-void CL_Snd_Restart(void)
+void CL_Snd_Shutdown(void)
 {
 }
 

Modified: trunk/code/qcommon/common.c
===================================================================
--- trunk/code/qcommon/common.c	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/qcommon/common.c	2011-06-17 23:29:19 UTC (rev 2042)
@@ -2408,10 +2408,10 @@
 		// Clean out any user and VM created cvars
 		Cvar_Restart(qtrue);
 		Com_ExecuteCfg();
+
+		// shut down sound system before restart
+		CL_Snd_Shutdown();
 		
-		// Restart sound subsystem so old handles are flushed
-		CL_Snd_Restart();
-
 		if(clientRestart)
 			CL_StartHunkUsers(qfalse);
 		

Modified: trunk/code/qcommon/qcommon.h
===================================================================
--- trunk/code/qcommon/qcommon.h	2011-06-16 22:51:12 UTC (rev 2041)
+++ trunk/code/qcommon/qcommon.h	2011-06-17 23:29:19 UTC (rev 2042)
@@ -996,7 +996,7 @@
 void CL_StartHunkUsers( qboolean rendererOnly );
 // start all the client stuff using the hunk
 
-void CL_Snd_Restart(void);
+void CL_Snd_Shutdown(void);
 // Restart sound subsystem
 
 void Key_KeynameCompletion( void(*callback)(const char *s) );



More information about the quake3-commits mailing list