Merge branch 'stable'

* stable:
  light: trace: fix MakeTnodes_r blowing up with ijed's rift1.map

# Conflicts:
#	light/trace.cc
This commit is contained in:
Eric Wasylishen 2016-07-21 01:51:23 -06:00
commit 191949e569
1 changed files with 10 additions and 7 deletions

View File

@ -18,6 +18,7 @@
*/
#include <light/light.hh>
#include <cassert>
#define TRACE_HIT_NONE 0
#define TRACE_HIT_SOLID (1 << 0)
@ -91,7 +92,6 @@ typedef struct faceinfo_s {
} faceinfo_t;
static tnode_t *tnodes;
static tnode_t *tnode_p;
static const bsp2_t *bsp_static;
static faceinfo_t *faceinfos;
@ -144,7 +144,9 @@ MakeTnodes_r(int nodenum, const bsp2_t *bsp)
bsp2_dnode_t *node;
bsp2_dleaf_t *leaf;
tnode = tnode_p++;
assert(nodenum >= 0);
assert(nodenum < bsp->numnodes);
tnode = &tnodes[nodenum];
node = bsp->dnodes + nodenum;
tnode->plane = bsp->dplanes + node->planenum;
@ -155,13 +157,14 @@ MakeTnodes_r(int nodenum, const bsp2_t *bsp)
tnode->dist = tnode->plane->dist;
for (i = 0; i < 2; i++) {
if (node->children[i] < 0) {
leaf = &bsp->dleafs[-node->children[i] - 1];
int childnum = node->children[i];
if (childnum < 0) {
leaf = &bsp->dleafs[-childnum - 1];
tnode->children[i] = leaf->contents;
tnode->childleafs[i] = leaf;
} else {
tnode->children[i] = tnode_p - tnodes;
MakeTnodes_r(node->children[i], bsp);
tnode->children[i] = childnum;
MakeTnodes_r(childnum, bsp);
}
}
}
@ -323,7 +326,7 @@ void
BSP_MakeTnodes(const bsp2_t *bsp)
{
bsp_static = bsp;
tnode_p = tnodes = (tnode_t *) malloc(bsp->numnodes * sizeof(tnode_t));
tnodes = (tnode_t *) malloc(bsp->numnodes * sizeof(tnode_t));
for (int i = 0; i < bsp->nummodels; i++)
MakeTnodes_r(bsp->dmodels[i].headnode[0], bsp);