]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - zone.c
SDL: reduce the sound buffer size (too much lag otherwise)
[xonotic/darkplaces.git] / zone.c
diff --git a/zone.c b/zone.c
index a945a85084be6d9c85301e19111825b319a3bb0c..0895f522649e83c6b634fa2f839798ff01fe442a 100644 (file)
--- a/zone.c
+++ b/zone.c
@@ -431,6 +431,7 @@ void *Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
                                {
                                        l->arrays[i].allocflags[j] = true;
                                        l->arrays[i].numflaggedrecords++;
+                                       memset(l->arrays[i].data + l->recordsize * j, 0, l->recordsize);
                                        return (void *)(l->arrays[i].data + l->recordsize * j);
                                }
                        }
@@ -438,7 +439,16 @@ void *Mem_ExpandableArray_AllocRecord(memexpandablearray_t *l)
        }
 }
 
-void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record)
+/*****************************************************************************
+ * IF YOU EDIT THIS:
+ * If this function was to change the size of the "expandable" array, you have
+ * to update r_shadow.c
+ * Just do a search for "range =", R_ShadowClearWorldLights would be the first
+ * function to look at. (And also seems like the only one?) You  might have to
+ * move the  call to Mem_ExpandableArray_IndexRange  back into for(...) loop's
+ * condition
+ */
+void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record) // const!
 {
        size_t i, j;
        unsigned char *p = (unsigned char *)record;
@@ -458,19 +468,24 @@ void Mem_ExpandableArray_FreeRecord(memexpandablearray_t *l, void *record)
        }
 }
 
-size_t Mem_ExpandableArray_IndexRange(memexpandablearray_t *l)
+size_t Mem_ExpandableArray_IndexRange(const memexpandablearray_t *l)
 {
-       size_t i, j, k;
-       if (!l->numarrays)
-               return 0;
-       i = l->numarrays - 1;
-       for (j = 0, k = 0;k < l->arrays[i].numflaggedrecords;j++)
-               if (l->arrays[i].allocflags[j])
-                       k++;
-       return l->numrecordsperarray * i + j;
+       size_t i, j, k, end = 0;
+       for (i = 0;i < l->numarrays;i++)
+       {
+               for (j = 0, k = 0;k < l->arrays[i].numflaggedrecords;j++)
+               {
+                       if (l->arrays[i].allocflags[j])
+                       {
+                               end = l->numrecordsperarray * i + j + 1;
+                               k++;
+                       }
+               }
+       }
+       return end;
 }
 
-void *Mem_ExpandableArray_RecordAtIndex(memexpandablearray_t *l, size_t index)
+void *Mem_ExpandableArray_RecordAtIndex(const memexpandablearray_t *l, size_t index)
 {
        size_t i, j;
        i = index / l->numrecordsperarray;
@@ -561,9 +576,10 @@ void MemStats_f(void)
 char* Mem_strdup (mempool_t *pool, const char* s)
 {
        char* p;
+       size_t sz = strlen (s) + 1;
        if (s == NULL) return NULL;
-       p = (char*)Mem_Alloc (pool, strlen (s) + 1);
-       strcpy (p, s);
+       p = (char*)Mem_Alloc (pool, sz);
+       strlcpy (p, s, sz);
        return p;
 }