diff options
author | Andrey Nazarov <skuller@skuller.net> | 2013-01-03 14:47:07 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2013-01-03 14:47:07 +0400 |
commit | 3f58c78ac4803f164a86b64efbed0f8a2ad88383 (patch) | |
tree | 4acf049414aa876afd260b727630c395ecd1bc77 | |
parent | 3cc4f0ae9b9867c4232124ee317bf5804683828e (diff) |
Allow BSP models to have a leaf as a head node.
Fixes a crash due to NULL headnode in BSP_TransformedLightPoint, and
properly clips to invisible models present in some maps.
-rw-r--r-- | src/common/bsp.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/common/bsp.c b/src/common/bsp.c index 9b21314..4868a5a 100644 --- a/src/common/bsp.c +++ b/src/common/bsp.c @@ -642,11 +642,19 @@ LOAD(Submodels) out->origin[j] = LittleFloat(in->origin[j]); } headnode = LittleLong(in->headnode); - if (headnode >= bsp->numnodes) { - // FIXME: headnode may be garbage for some models (a leaf perhaps) - Com_DPrintf("%s: bad headnode\n", __func__); - out->headnode = NULL; + if (headnode & 0x80000000) { + // be careful, some models have no nodes, just a leaf + headnode = ~headnode; + if (headnode >= bsp->numleafs) { + DEBUG("bad headleaf"); + return Q_ERR_BAD_INDEX; + } + out->headnode = (mnode_t *)(bsp->leafs + headnode); } else { + if (headnode >= bsp->numnodes) { + DEBUG("bad headnode"); + return Q_ERR_BAD_INDEX; + } out->headnode = bsp->nodes + headnode; } #if USE_REF |