i cant get rid of seg fault error

which is why trace is set to return on lol = 1

the first colision sets lol = 1 and it seg faults when i move around and hit that face 2

u can see that im doing a trace on just on face 2 for testing

what i am i missing here

i know something is working since it crashes when i hit that wall wtf

am i that big of a noob?

jus tell me

TNode node;

TPlane plane;

TLeaf leaf;

TBrush brush;

TBrushSide brushSide;

void CheckBrush(int brushIndex, int nodeIndex, tVector3 start, tVector3 end, tVector3 planeNormal) {

```
//printf("CheckBrush: %d
```

", brushIndex);

```
float startFraction = -1.0f;
float endFraction = 1.0f;
bool startsOut = false;
bool endsOut = false;
bool outputAllSolid = false;
bool outputStartOut = true;
node = lMap.mNodes[nodeIndex];
plane = lMap.mPlanes[node.mPlane];
leaf = lMap.mLeaves[-(nodeIndex + 1)];
brush = lMap.mBrushes[lMap.mLeafBrushes[leaf.mLeafBrush + brushIndex].mBrushIndex];
int i;
for (i = 0; i < brush.mNbBrushSides; i++) {
brushSide = lMap.mBrushSides[brush.mBrushSide + i];
plane = lMap.mPlanes[brushSide.mPlaneIndex];
float startDistance = DotProduct(start, planeNormal) - plane.mDistance;
float endDistance = DotProduct(end, planeNormal) - plane.mDistance;
if (startDistance > 0) startsOut = true;
if (endDistance > 0) endsOut = true;
// make sure the trace isn't completely on one side of the brush
if (startDistance > 0 && endDistance > 0)
{ // both are in front of the plane, its outside of this brush
return;
}
if (startDistance <= 0 && endDistance <= 0)
{ // both are behind this plane, it will get clipped by another one
continue;
}
if (startDistance > endDistance)
{ // line is entering into the brush
float fraction = (startDistance - EPSILON) / (startDistance - endDistance);
if (fraction > startFraction) startFraction = fraction;
}
else
{ // line is leaving the brush
float fraction = (startDistance + EPSILON) / (startDistance - endDistance);
if (fraction < endFraction) endFraction = fraction;
}
}
if (startsOut == false) {
outputStartOut = false;
if (endsOut == false) outputAllSolid = true;
return;
}
if (startFraction < endFraction) {
if (startFraction > -1 && startFraction < outputFraction) {
if (startFraction < 0) startFraction = 0;
outputFraction = startFraction;
}
}
```

}

void CheckNode(int nodeIndex, float startFraction, float endFraction,

tVector3 start, tVector3 end) {

```
//printf("CheckNode: %d
```

", nodeIndex);

```
node = lMap.mNodes[nodeIndex];
plane = lMap.mPlanes[node.mPlane];
tVector3 planeNormal;
planeNormal.x = plane.mNormal[0];
planeNormal.y = plane.mNormal[1];
planeNormal.z = plane.mNormal[2];
if (nodeIndex < 0) { // this is a leaf
leaf = lMap.mLeaves[-(nodeIndex + 1)];
int i;
for (i = 0; i < leaf.mNbLeafBrushes; i++) {
brush = lMap.mBrushes[lMap.mLeafBrushes[leaf.mLeafBrush + i].mBrushIndex];
//TBrush* brush2 = lMap.mBrushes[lMap.mLeafBrushes[leaf.mLeafBrush + i].mBrushIndex];
//&& (BSP.shaders[brush.mTextureIndex].contentFlags & 1)
if (brush.mNbBrushSides > 0)
CheckBrush(i, nodeIndex, start, end, planeNormal);
}
// don't have to do anything else for leaves
return;
}
float startDistance = DotProduct(start, planeNormal) - plane.mDistance;
float endDistance = DotProduct(end, planeNormal) - plane.mDistance;
//printf("mChildren: %d
```

", node.mChildren[0]);

```
//return;
if (startDistance >= 0 && endDistance >= 0) {
// both points are in front of the plane
if (node.mChildren[0] > 0) {
// so check the front child
CheckNode( node.mChildren[0], startFraction, endFraction, start, end );
}
} else if (startDistance < 0 && endDistance < 0) {
// both points are behind the plane
if (node.mChildren[1] > 0) {
// so check the back child
CheckNode(node.mChildren[1], startFraction, endFraction, start, end);
}
} else {
//return;
int side;
float fraction1, fraction2, middleFraction, inverseDistance;
// STEP 1: split the segment into two
if (startDistance < endDistance) {
side = 1; // back
inverseDistance = 1.0f / (startDistance - endDistance);
fraction1 = (startDistance + EPSILON) * inverseDistance;
fraction2 = (startDistance + EPSILON) * inverseDistance;
} else if (endDistance < startDistance) {
side = 0; // front
inverseDistance = 1.0f / (startDistance - endDistance);
fraction1 = (startDistance + EPSILON) * inverseDistance;
fraction2 = (startDistance - EPSILON) * inverseDistance;
} else {
side = 0; // front
fraction1 = 1.0f;
fraction2 = 0.0f;
}
// STEP 2: make sure the numbers are valid
if (fraction1 < 0.0f) fraction1 = 0.0f;
else if (fraction1 > 1.0f) fraction1 = 1.0f;
if (fraction2 < 0.0f) fraction2 = 0.0f;
else if (fraction2 > 1.0f) fraction2 = 1.0f;
// STEP 3: calculate the middle point for the first side
middleFraction = startFraction + (endFraction - startFraction) * fraction1;
tVector3 middle;
//middle = tVector3(x, y, z);
middle.x = start.x + fraction1 * (end.x - start.x);
middle.y = start.y + fraction1 * (end.y - start.y);
middle.z = start.z + fraction1 * (end.z - start.z);
// STEP 4: check the first side
CheckNode(node.mChildren[0], startFraction, middleFraction, start, middle);
// STEP 5: calculate the middle point for the second side
middleFraction = startFraction + (endFraction - startFraction) * fraction2;
middle.x = start.x + fraction2 * (end.x - start.x);
middle.y = start.y + fraction2 * (end.y - start.y);
middle.z = start.z + fraction2 * (end.z - start.z);
// STEP 6: check the second side
CheckNode(node.mChildren[1], middleFraction, endFraction, middle, end);
}
```

}

void Trace(tVector3 inputStart, int ummnode) {

```
if (lol == 1) return;
//outputFraction = 0.0f;
float startFraction = 0.0f;
float endFraction = 1.0f;
tVector3 wallNormal;
// Calculate the cross product with the non communitive equation
wallNormal.x = lMap.mFaces[2].mNormal[0];
wallNormal.y = lMap.mFaces[2].mNormal[1];
wallNormal.z = lMap.mFaces[2].mNormal[2];
tVector3 inputEnd;
// walk through the BSP tree
CheckNode(ummnode, startFraction, endFraction, inputStart, inputEnd);
tVector3 outputEnd;
if (outputFraction == 1.0f) { // nothing blocked the trace
outputEnd = inputEnd;
lol = 0;
} else { // collided with something
//outputFraction == 1.0f;
lol = 1;
//printf("colided
```

");

```
//mPos.z = -mPos.z;
//mPos.x = -mPos.x;
//mPos.z = z_m_1 + 1;
//outputEnd[i] = inputStart[i] + outputFraction * (inputEnd[i] - inputStart[i]);
outputEnd.x = inputStart.x + outputFraction * (inputEnd.x - inputStart.x);
outputEnd.y = inputStart.y + outputFraction * (inputEnd.y - inputStart.y);
outputEnd.z = inputStart.z + outputFraction * (inputEnd.z - inputStart.z);
}
```

}