shithub: qk1

Download patch

ref: 9c2610853f765d616e247bd7b4ae714028f45f05
parent: 83bd0b845096b4e3c4a6bca6645c154c2e3da025
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Oct 10 20:40:39 EDT 2023

snd: allow too many sounds

--- a/snd.c
+++ b/snd.c
@@ -35,8 +35,10 @@
 	int p;
 	int n;
 };
-static Chan chans[Nchan], *che;
 
+static int nchan;
+static Chan *chans, *che;
+
 static int afd = -1, mixbufi;
 static uchar mixbufs[2][Snbuf], *mixbuf = mixbufs[0];
 static vlong sndt, sampt;
@@ -686,9 +688,9 @@
 
 	if(sfx == nil)
 		return;
-	if(che >= chans + nelem(chans)){
-		fprint(2, "staticsfx: channel overflow\n");
-		return;
+	if(che >= chans + nchan){
+		nchan *= 2;
+		chans = realloc(chans, nchan*sizeof(*chans));
 	}
 	c = che++;
 	if(sc = loadsfx(sfx), sc == nil)
@@ -851,6 +853,8 @@
 	Cvar_RegisterVariable(&ambient_level);
 	Cvar_RegisterVariable(&ambient_fade);
 
+	nchan = Nchan;
+	chans = calloc(nchan, sizeof(*chans));
 	known_sfx = Hunk_Alloc(MAX_SFX * sizeof *known_sfx);
 	num_sfx = 0;
 	ambsfx[Ambwater] = precachesfx("ambience/water1.wav");