]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
fixed transparent color in HL textures (was red, should be blue... oops)
[xonotic/darkplaces.git] / model_brush.c
index 4fa418f3710256877a559e7c94bebccab59ac885..3f09262d54aaadff80939fc380e20bd6808f09a5 100644 (file)
@@ -39,36 +39,7 @@ void Mod_BrushInit (void)
        memset (mod_novis, 0xff, sizeof(mod_novis));
 }
 
-/*
-===============
-Mod_PointInLeaf
-===============
-*/
-mleaf_t *Mod_PointInLeaf (vec3_t p, model_t *model)
-{
-       mnode_t         *node;
-       float           d;
-       mplane_t        *plane;
-       
-       if (!model || !model->nodes)
-               Sys_Error ("Mod_PointInLeaf: bad model");
-
-       node = model->nodes;
-       while (1)
-       {
-               if (node->contents < 0)
-                       return (mleaf_t *)node;
-               plane = node->plane;
-               d = DotProduct (p,plane->normal) - plane->dist;
-               if (d > 0)
-                       node = node->children[0];
-               else
-                       node = node->children[1];
-       }
-       
-       return NULL;    // never reached
-}
-
+// Mod_PointInLeaf moved to cpu_noasm.c
 
 /*
 ===================
@@ -122,7 +93,7 @@ byte *Mod_LeafPVS (mleaf_t *leaf, model_t *model)
        return Mod_DecompressVis (leaf->compressed_vis, model);
 }
 
-byte   *mod_base;
+extern byte    *mod_base;
 
 extern cvar_t r_fullbrights;
 
@@ -139,7 +110,8 @@ void Mod_LoadTextures (lump_t *l)
        texture_t       *anims[10];
        texture_t       *altanims[10];
        dmiptexlump_t *m;
-       byte *data;
+       byte    *data;
+       int             *dofs;
 
        if (!l->filelen)
        {
@@ -152,26 +124,38 @@ void Mod_LoadTextures (lump_t *l)
        m->nummiptex = LittleLong (m->nummiptex);
        
        loadmodel->numtextures = m->nummiptex;
-       loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures) , loadname);
+       loadmodel->textures = Hunk_AllocName (m->nummiptex * sizeof(*loadmodel->textures), va("%s texture headers", loadname));
 
+       // just to work around bounds checking when debugging with it (array index out of bounds error thing)
+       dofs = m->dataofs;
        for (i=0 ; i<m->nummiptex ; i++)
        {
-               m->dataofs[i] = LittleLong(m->dataofs[i]);
-               if (m->dataofs[i] == -1)
+               dofs[i] = LittleLong(dofs[i]);
+               if (dofs[i] == -1)
                        continue;
-               mt = (miptex_t *)((byte *)m + m->dataofs[i]);
+               mt = (miptex_t *)((byte *)m + dofs[i]);
                mt->width = LittleLong (mt->width);
                mt->height = LittleLong (mt->height);
                for (j=0 ; j<MIPLEVELS ; j++)
                        mt->offsets[j] = LittleLong (mt->offsets[j]);
                
                if ( (mt->width & 15) || (mt->height & 15) )
-                       Sys_Error ("Texture %s is not 16 aligned", mt->name);
+                       Host_Error ("Texture %s is not 16 aligned", mt->name);
                // LordHavoc: rewriting the map texture loader for GLQuake
-               tx = Hunk_AllocName (sizeof(texture_t), loadname );
+               tx = Hunk_AllocName (sizeof(texture_t), va("%s textures", loadname));
                loadmodel->textures[i] = tx;
 
-               memcpy (tx->name, mt->name, sizeof(tx->name));
+               // LordHavoc: force all names to lowercase and make sure they are terminated while copying
+               for (j = 0;mt->name[j] && j < 15;j++)
+               {
+                       if (mt->name[j] >= 'A' && mt->name[j] <= 'Z')
+                               tx->name[j] = mt->name[j] + ('a' - 'A');
+                       else
+                               tx->name[j] = mt->name[j];
+               }
+               for (;j < 16;j++)
+                       tx->name[j] = 0;
+
                tx->width = mt->width;
                tx->height = mt->height;
                for (j=0 ; j<MIPLEVELS ; j++)
@@ -179,23 +163,54 @@ void Mod_LoadTextures (lump_t *l)
                freeimage = TRUE;
                bytesperpixel = 4;
                fullbrights = FALSE;
-               transparent = FALSE;
-               data = loadimagepixels(mt->name, FALSE, tx->width, tx->height);
+               transparent = TRUE;
+               data = loadimagepixels(tx->name, FALSE, 0, 0); //tx->width, tx->height);
                if (!data) // no external texture found
                {
                        freeimage = FALSE;
+                       transparent = FALSE;
                        bytesperpixel = 1;
-                       if (!hlbsp && mt->offsets[0]) // texture included
+                       if (mt->offsets[0]) // texture included
                        {
                                data = (byte *)((int) mt + mt->offsets[0]);
-                               if (r_fullbrights.value && mt->name[0] != '*')
+                               if (hlbsp)
+                               {
+                                       byte *in, *out, *pal;
+                                       int palsize, d, p;
+                                       bytesperpixel = 4;
+                                       freeimage = TRUE;
+                                       in = data;
+                                       data = out = qmalloc(mt->width * mt->height * 4);
+                                       pal = in + (((mt->width * mt->height) * 85) >> 6);
+                                       palsize = pal[1] * 0x100 + pal[0];
+                                       if (palsize >= 256)
+                                               palsize = 255;
+                                       pal += 2;
+                                       for (d = 0;d < mt->width * mt->height;d++)
+                                       {
+                                               p = (*in++) * 3;
+                                               out[0] = pal[p];
+                                               out[1] = pal[p+1];
+                                               out[2] = pal[p+2];
+                                               out[3] = 255;
+                                               if (out[0] == 0 && out[1] == 0 && out[2] == 255) // HL transparent color (pure blue)
+                                               {
+                                                       out[0] = out[1] = out[2] = out[3] = 0;
+                                                       transparent = TRUE;
+                                               }
+                                               out += 4;
+                                       }
+                               }
+                               else if (r_fullbrights.value && tx->name[0] != '*')
                                {
                                        for (j = 0;j < tx->width*tx->height;j++)
+                                       {
                                                if (data[j] >= 224) // fullbright
                                                {
                                                        fullbrights = TRUE;
                                                        break;
                                                }
+                                       }
                                }
                        }
                        else // no texture, and no external replacement texture was found
@@ -206,64 +221,41 @@ void Mod_LoadTextures (lump_t *l)
                }
                else
                {
-                       for (j = 0;j < image_width*image_height;j++)
-                               if (data[j*4+3] < 255)
-                               {
-                                       transparent = TRUE;
-                                       break;
-                               }
+                       tx->width = image_width;
+                       tx->height = image_height;
                }
-               if (!hlbsp && !strncmp(mt->name,"sky",3)) // LordHavoc: HL sky textures are entirely unrelated
+               if (!hlbsp && !strncmp(tx->name,"sky",3) && tx->width == 256 && tx->height == 128) // LordHavoc: HL sky textures are entirely unrelated
                {
                        tx->transparent = FALSE;
                        R_InitSky (data, bytesperpixel);
                }
                else
                {
-                       tx->transparent = transparent;
                        if (fullbrights)
                        {
                                char name[64];
                                byte *data2;
-                               data2 = malloc(tx->width*tx->height);
+                               tx->transparent = false;
+                               data2 = qmalloc(tx->width*tx->height);
                                for (j = 0;j < tx->width*tx->height;j++)
                                        data2[j] = data[j] >= 224 ? 0 : data[j]; // no fullbrights
-                               tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, transparent, 1);
+                               tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data2, true, false, 1);
                                strcpy(name, tx->name);
                                strcat(name, "_glow");
                                for (j = 0;j < tx->width*tx->height;j++)
                                        data2[j] = data[j] >= 224 ? data[j] : 0; // only fullbrights
-                               tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, transparent, 1);
-                               free(data2);
+                               tx->gl_glowtexturenum = GL_LoadTexture (name, tx->width, tx->height, data2, true, false, 1);
+                               qfree(data2);
                        }
                        else
                        {
+                               tx->transparent = transparent;
                                tx->gl_texturenum = GL_LoadTexture (tx->name, tx->width, tx->height, data, true, transparent, bytesperpixel);
                                tx->gl_glowtexturenum = 0;
                        }
                }
                if (freeimage)
-                       free(data);
-
-               /*
-               pixels = mt->width*mt->height/64*85;
-               tx = Hunk_AllocName (sizeof(texture_t) +pixels, loadname );
-               loadmodel->textures[i] = tx;
-
-               memcpy (tx->name, mt->name, sizeof(tx->name));
-               tx->width = mt->width;
-               tx->height = mt->height;
-               for (j=0 ; j<MIPLEVELS ; j++)
-                       tx->offsets[j] = mt->offsets[j] + sizeof(texture_t) - sizeof(miptex_t);
-               // the pixels immediately follow the structures
-               memcpy ( tx+1, mt+1, pixels);
-               
-
-               if (!strncmp(mt->name,"sky",3)) 
-                       R_InitSky (tx);
-               else
-                       tx->gl_texturenum = GL_LoadTexture (mt->name, tx->width, tx->height, (byte *)(tx+1), true, false, 1);
-               */
+                       qfree(data);
        }
 
 //
@@ -328,7 +320,7 @@ void Mod_LoadTextures (lump_t *l)
                                        altmax = num+1;
                        }
                        else
-                               Sys_Error ("Bad animating texture %s", tx->name);
+                               Host_Error ("Bad animating texture %s", tx->name);
                }
                
 #define        ANIM_CYCLE      2
@@ -337,7 +329,7 @@ void Mod_LoadTextures (lump_t *l)
                {
                        tx2 = anims[j];
                        if (!tx2)
-                               Sys_Error ("Missing frame %i of %s",j, tx->name);
+                               Host_Error ("Missing frame %i of %s",j, tx->name);
                        tx2->anim_total = max * ANIM_CYCLE;
                        tx2->anim_min = j * ANIM_CYCLE;
                        tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -349,7 +341,7 @@ void Mod_LoadTextures (lump_t *l)
                {
                        tx2 = altanims[j];
                        if (!tx2)
-                               Sys_Error ("Missing frame %i of %s",j, tx->name);
+                               Host_Error ("Missing frame %i of %s",j, tx->name);
                        tx2->anim_total = altmax * ANIM_CYCLE;
                        tx2->anim_min = j * ANIM_CYCLE;
                        tx2->anim_max = (j+1) * ANIM_CYCLE;
@@ -372,11 +364,9 @@ void Mod_LoadLighting (lump_t *l)
        byte d;
        char litfilename[1024];
        loadmodel->lightdata = NULL;
-       if (!l->filelen)
-               return;
        if (hlbsp) // LordHavoc: load the colored lighting data straight
        {
-               loadmodel->lightdata = Hunk_AllocName ( l->filelen, loadname);
+               loadmodel->lightdata = Hunk_AllocName ( l->filelen, va("%s lightmaps", loadname));
                memcpy (loadmodel->lightdata, mod_base + l->fileofs, l->filelen);
        }
        else // LordHavoc: bsp version 29 (normal white lighting)
@@ -393,6 +383,7 @@ void Mod_LoadLighting (lump_t *l)
                                i = LittleLong(((int *)data)[1]);
                                if (i == 1)
                                {
+                                       Con_DPrintf("%s loaded", litfilename);
                                        loadmodel->lightdata = data + 8;
                                        return;
                                }
@@ -403,7 +394,9 @@ void Mod_LoadLighting (lump_t *l)
                                Con_Printf("Corrupt .lit file (old version?), ignoring\n");
                }
                // LordHavoc: oh well, expand the white lighting data
-               loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, litfilename);
+               if (!l->filelen)
+                       return;
+               loadmodel->lightdata = Hunk_AllocName ( l->filelen*3, va("%s lightmaps", loadname));
                in = loadmodel->lightdata + l->filelen*2; // place the file at the end, so it will not be overwritten until the very last write
                out = loadmodel->lightdata;
                memcpy (in, mod_base + l->fileofs, l->filelen);
@@ -430,7 +423,7 @@ void Mod_LoadVisibility (lump_t *l)
                loadmodel->visdata = NULL;
                return;
        }
-       loadmodel->visdata = Hunk_AllocName ( l->filelen, loadname);    
+       loadmodel->visdata = Hunk_AllocName ( l->filelen, va("%s visdata", loadname));
        memcpy (loadmodel->visdata, mod_base + l->fileofs, l->filelen);
 }
 
@@ -450,7 +443,7 @@ void Mod_LoadEntities (lump_t *l)
                loadmodel->entities = NULL;
                return;
        }
-       loadmodel->entities = Hunk_AllocName ( l->filelen, loadname);   
+       loadmodel->entities = Hunk_AllocName ( l->filelen, va("%s entities", loadname));
        memcpy (loadmodel->entities, mod_base + l->fileofs, l->filelen);
 
        if (isworldmodel)
@@ -471,9 +464,9 @@ void Mod_LoadVertexes (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s vertices", loadname));
 
        loadmodel->vertexes = out;
        loadmodel->numvertexes = count;
@@ -499,9 +492,9 @@ void Mod_LoadSubmodels (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s submodels", loadname));
 
        loadmodel->submodels = out;
        loadmodel->numsubmodels = count;
@@ -535,9 +528,9 @@ void Mod_LoadEdges (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( (count + 1) * sizeof(*out), loadname);   
+       out = Hunk_AllocName ( (count + 1) * sizeof(*out), va("%s edges", loadname));
 
        loadmodel->edges = out;
        loadmodel->numedges = count;
@@ -558,23 +551,24 @@ void Mod_LoadTexinfo (lump_t *l)
 {
        texinfo_t *in;
        mtexinfo_t *out;
-       int     i, j, count;
+       int     i, j, k, count;
        int             miptex;
        float   len1, len2;
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s texinfo", loadname));
 
        loadmodel->texinfo = out;
        loadmodel->numtexinfo = count;
 
        for ( i=0 ; i<count ; i++, in++, out++)
        {
-               for (j=0 ; j<8 ; j++)
-                       out->vecs[0][j] = LittleFloat (in->vecs[0][j]);
+               for (k=0 ; k<2 ; k++)
+                       for (j=0 ; j<4 ; j++)
+                               out->vecs[k][j] = LittleFloat (in->vecs[k][j]);
                len1 = Length (out->vecs[0]);
                len2 = Length (out->vecs[1]);
                len1 = (len1 + len2)/2;
@@ -600,19 +594,19 @@ void Mod_LoadTexinfo (lump_t *l)
                {
                        out->texture = r_notexture_mip; // checkerboard texture
                        out->flags = 0;
+                       out->texture->transparent = FALSE;
                }
                else
                {
                        if (miptex >= loadmodel->numtextures)
-                               Sys_Error ("miptex >= loadmodel->numtextures");
+                               Host_Error ("miptex >= loadmodel->numtextures");
                        out->texture = loadmodel->textures[miptex];
                        if (!out->texture)
                        {
                                out->texture = r_notexture_mip; // texture not found
                                out->flags = 0;
-                       }
-                       else
                                out->texture->transparent = FALSE;
+                       }
                }
        }
 }
@@ -666,7 +660,7 @@ void CalcSurfaceExtents (msurface_t *s)
                s->texturemins[i] = bmins[i] * 16;
                s->extents[i] = (bmaxs[i] - bmins[i]) * 16;
                if ( !(tex->flags & TEX_SPECIAL) && s->extents[i] > 512 /* 256 */ )
-                       Sys_Error ("Bad surface extents");
+                       Host_Error ("Bad surface extents");
        }
 }
 
@@ -688,9 +682,9 @@ void Mod_LoadFaces (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s faces", loadname));
 
        loadmodel->surfaces = out;
        loadmodel->numsurfaces = count;
@@ -787,9 +781,9 @@ void Mod_LoadNodes (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s nodes", loadname));
 
        loadmodel->nodes = out;
        loadmodel->numnodes = count;
@@ -834,9 +828,9 @@ void Mod_LoadLeafs (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s leafs", loadname));
 
        loadmodel->leafs = out;
        loadmodel->numleafs = count;
@@ -891,42 +885,85 @@ void Mod_LoadClipnodes (lump_t *l)
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s clipnodes", loadname));
 
        loadmodel->clipnodes = out;
        loadmodel->numclipnodes = count;
 
-       hull = &loadmodel->hulls[1];
-       hull->clipnodes = out;
-       hull->firstclipnode = 0;
-       hull->lastclipnode = count-1;
-       hull->planes = loadmodel->planes;
-       hull->clip_mins[0] = -16;
-       hull->clip_mins[1] = -16;
-       hull->clip_mins[2] = -24;
-       hull->clip_maxs[0] = 16;
-       hull->clip_maxs[1] = 16;
-       hull->clip_maxs[2] = 32;
-
-       hull = &loadmodel->hulls[2];
-       hull->clipnodes = out;
-       hull->firstclipnode = 0;
-       hull->lastclipnode = count-1;
-       hull->planes = loadmodel->planes;
-       hull->clip_mins[0] = -32;
-       hull->clip_mins[1] = -32;
-       hull->clip_mins[2] = -24;
-       hull->clip_maxs[0] = 32;
-       hull->clip_maxs[1] = 32;
-       hull->clip_maxs[2] = 64;
+       if (hlbsp)
+       {
+               hull = &loadmodel->hulls[1];
+               hull->clipnodes = out;
+               hull->firstclipnode = 0;
+               hull->lastclipnode = count-1;
+               hull->planes = loadmodel->planes;
+               hull->clip_mins[0] = -16;
+               hull->clip_mins[1] = -16;
+               hull->clip_mins[2] = -36;
+               hull->clip_maxs[0] = 16;
+               hull->clip_maxs[1] = 16;
+               hull->clip_maxs[2] = 36;
+
+               hull = &loadmodel->hulls[2];
+               hull->clipnodes = out;
+               hull->firstclipnode = 0;
+               hull->lastclipnode = count-1;
+               hull->planes = loadmodel->planes;
+               hull->clip_mins[0] = -32;
+               hull->clip_mins[1] = -32;
+               hull->clip_mins[2] = -32;
+               hull->clip_maxs[0] = 32;
+               hull->clip_maxs[1] = 32;
+               hull->clip_maxs[2] = 32;
+
+               hull = &loadmodel->hulls[3];
+               hull->clipnodes = out;
+               hull->firstclipnode = 0;
+               hull->lastclipnode = count-1;
+               hull->planes = loadmodel->planes;
+               hull->clip_mins[0] = -16;
+               hull->clip_mins[1] = -16;
+               hull->clip_mins[2] = -18;
+               hull->clip_maxs[0] = 16;
+               hull->clip_maxs[1] = 16;
+               hull->clip_maxs[2] = 18;
+       }
+       else
+       {
+               hull = &loadmodel->hulls[1];
+               hull->clipnodes = out;
+               hull->firstclipnode = 0;
+               hull->lastclipnode = count-1;
+               hull->planes = loadmodel->planes;
+               hull->clip_mins[0] = -16;
+               hull->clip_mins[1] = -16;
+               hull->clip_mins[2] = -24;
+               hull->clip_maxs[0] = 16;
+               hull->clip_maxs[1] = 16;
+               hull->clip_maxs[2] = 32;
+
+               hull = &loadmodel->hulls[2];
+               hull->clipnodes = out;
+               hull->firstclipnode = 0;
+               hull->lastclipnode = count-1;
+               hull->planes = loadmodel->planes;
+               hull->clip_mins[0] = -32;
+               hull->clip_mins[1] = -32;
+               hull->clip_mins[2] = -24;
+               hull->clip_maxs[0] = 32;
+               hull->clip_maxs[1] = 32;
+               hull->clip_maxs[2] = 64;
+       }
 
        for (i=0 ; i<count ; i++, out++, in++)
        {
                out->planenum = LittleLong(in->planenum);
                out->children[0] = LittleShort(in->children[0]);
                out->children[1] = LittleShort(in->children[1]);
+               if (out->children[0] >= count || out->children[1] >= count)
+                       Host_Error("Corrupt clipping hull (out of range child)\n");
        }
 }
 
@@ -948,7 +985,7 @@ void Mod_MakeHull0 (void)
        
        in = loadmodel->nodes;
        count = loadmodel->numnodes;
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s hull0", loadname));
 
        hull->clipnodes = out;
        hull->firstclipnode = 0;
@@ -982,9 +1019,9 @@ void Mod_LoadMarksurfaces (lump_t *l)
        
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s marksurfaces", loadname));
 
        loadmodel->marksurfaces = out;
        loadmodel->nummarksurfaces = count;
@@ -993,7 +1030,7 @@ void Mod_LoadMarksurfaces (lump_t *l)
        {
                j = LittleShort(in[i]);
                if (j >= loadmodel->numsurfaces)
-                       Sys_Error ("Mod_ParseMarksurfaces: bad surface number");
+                       Host_Error ("Mod_ParseMarksurfaces: bad surface number");
                out[i] = loadmodel->surfaces + j;
        }
 }
@@ -1010,9 +1047,9 @@ void Mod_LoadSurfedges (lump_t *l)
        
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*sizeof(*out), loadname);   
+       out = Hunk_AllocName ( count*sizeof(*out), va("%s surfedges", loadname));
 
        loadmodel->surfedges = out;
        loadmodel->numsurfedges = count;
@@ -1037,9 +1074,9 @@ void Mod_LoadPlanes (lump_t *l)
        
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
-               Sys_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
+               Host_Error ("MOD_LoadBmodel: funny lump size in %s",loadmodel->name);
        count = l->filelen / sizeof(*in);
-       out = Hunk_AllocName ( count*2*sizeof(*out), loadname); 
+       out = Hunk_AllocName ( count*2*sizeof(*out), va("%s planes", loadname));
 
        loadmodel->planes = out;
        loadmodel->numplanes = count;
@@ -1077,8 +1114,8 @@ void Mod_LoadBrushModel (model_t *mod, void *buffer)
        header = (dheader_t *)buffer;
 
        i = LittleLong (header->version);
-       if (i != BSPVERSION & i != 30)
-               Sys_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
+       if (i != BSPVERSION && i != 30)
+               Host_Error ("Mod_LoadBrushModel: %s has wrong version number (%i should be %i or 30 (HalfLife))", mod->name, i, BSPVERSION);
        hlbsp = i == 30;
        halflifebsp.value = hlbsp;