shithub: choc

Download patch

ref: cd116c36b611ffca0a4326130ac58504ce4b8f45
parent: 79446c49acfeb8b97fc535268cea4d9343cbaadf
author: Simon Howard <fraggle@gmail.com>
date: Sat Nov 27 14:39:14 EST 2010

When generating the texture name lookup hash table, add new entries to
the end of chains. This way, entries earlier in the texture list trump
later entries with the same name.
This fixes a bug with the wrong sky being shown in Spooky01.wad (thanks
Porsche Monty).

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2172

--- a/src/r_data.c
+++ b/src/r_data.c
@@ -413,6 +413,7 @@
 
 static void GenerateTextureHashTable(void)
 {
+    texture_t **rover;
     int i;
     int key;
 
@@ -429,12 +430,25 @@
 
         textures[i]->index = i;
 
-        // Hook into hash table
+        // Vanilla Doom does a linear search of the texures array
+        // and stops at the first entry it finds.  If there are two
+        // entries with the same name, the first one in the array
+        // wins. The new entry must therefore be added at the end
+        // of the hash chain, so that earlier entries win.
 
         key = W_LumpNameHash(textures[i]->name) % numtextures;
 
-        textures[i]->next = textures_hashtable[key];
-        textures_hashtable[key] = textures[i];
+        rover = &textures_hashtable[key];
+
+        while (*rover != NULL)
+        {
+            rover = &(*rover)->next;
+        }
+
+        // Hook into hash table
+
+        textures[i]->next = NULL;
+        *rover = textures[i];
     }
 }