From: divverent <divverent@61c419a2-8eb2-4b30-bcec-8cead039b335>
Date: Sat, 14 Feb 2009 18:14:30 +0000 (+0000)
Subject: fix multiple bugs with the limit extension
X-Git-Tag: svn-r421~229
X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e7f13faa4bb5ab02eb892ee43ee16b83a22221e1;p=xonotic%2Fnetradiant.git

fix multiple bugs with the limit extension


git-svn-id: svn://svn.icculus.org/netradiant/trunk@191 61c419a2-8eb2-4b30-bcec-8cead039b335
---

diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c
index b4b6349f..9e41af4f 100644
--- a/tools/quake3/q3map2/lightmaps_ydnar.c
+++ b/tools/quake3/q3map2/lightmaps_ydnar.c
@@ -865,9 +865,9 @@ static int CompareSurfaceInfo( const void *a, const void *b )
 	bInfo = &surfaceInfos[ *((int*) b) ];
 	
 	/* model first */
-	if( aInfo->model < bInfo->model )
+	if( aInfo->modelindex < bInfo->modelindex )
 		return 1;
-	else if( aInfo->model > bInfo->model )
+	else if( aInfo->modelindex > bInfo->modelindex )
 		return -1;
 	
 	/* then lightmap status */
@@ -997,7 +997,7 @@ void SetupSurfaceLightmaps( void )
 				VectorClear( entityOrigin );
 			
 			/* basic setup */
-			info->model = model;
+			info->modelindex = i;
 			info->lm = NULL;
 			info->plane = NULL;
 			info->firstSurfaceCluster = numSurfaceClusters;
diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h
index 3224d8e9..4819ff30 100644
--- a/tools/quake3/q3map2/q3map2.h
+++ b/tools/quake3/q3map2/q3map2.h
@@ -1421,7 +1421,7 @@ rawGridPoint_t;
 
 typedef struct surfaceInfo_s
 {
-	bspModel_t			*model;
+	int					modelindex;
 	shaderInfo_t		*si;
 	rawLightmap_t		*lm;
 	int					parentSurfaceNum, childSurfaceNum;
@@ -2328,7 +2328,7 @@ Q_EXTERN int*				bspLeafSurfaces Q_ASSIGN(NULL);
 
 Q_EXTERN int				numBSPLeafBrushes Q_ASSIGN( 0 );
 Q_EXTERN int				allocatedBSPLeafBrushes Q_ASSIGN( 0 );
-Q_EXTERN int*				bspLeafBrushes Q_ASSIGN(0);
+Q_EXTERN int*				bspLeafBrushes Q_ASSIGN(NULL);
 
 Q_EXTERN int				numBSPBrushes Q_ASSIGN( 0 );
 Q_EXTERN int				allocatedBSPBrushes Q_ASSIGN( 0 );
diff --git a/tools/quake3/q3map2/writebsp.c b/tools/quake3/q3map2/writebsp.c
index 70a382dd..96e8ce29 100644
--- a/tools/quake3/q3map2/writebsp.c
+++ b/tools/quake3/q3map2/writebsp.c
@@ -199,7 +199,7 @@ recursively emit the bsp nodes
 int EmitDrawNode_r( node_t *node )
 {
 	bspNode_t	*n;
-	int			i;
+	int			i, n0;
 	
 	
 	/* check for leafnode */
@@ -211,7 +211,8 @@ int EmitDrawNode_r( node_t *node )
 	
 	/* emit a node */
 	AUTOEXPAND_BY_REALLOC_BSP(Nodes, 1024);
-	n = &bspNodes[ numBSPNodes ];
+	n0 = numBSPNodes;
+	n = &bspNodes[ n0 ];
 	numBSPNodes++;
 	
 	VectorCopy (node->mins, n->mins);
@@ -235,6 +236,8 @@ int EmitDrawNode_r( node_t *node )
 		{
 			n->children[i] = numBSPNodes;	
 			EmitDrawNode_r (node->children[i]);
+			// n may have become invalid here, so...
+			n = &bspNodes[ n0 ];
 		}
 	}