Okay, I found the bug!

So, here’s the insphere() routine. Well, I’ll post it below but first, I was only so hesitant to post it because it relies on A LOT of things. A ton of macros and some external functions. But here’s just the function that I’m using by itself (btw, REAL is #define REAL float) :

```
__device__ REAL insphere(REAL *pa, REAL *pb, REAL *pc, REAL *pd, REAL *pe) {
REAL aex, bex, cex, dex;
REAL aey, bey, cey, dey;
REAL aez, bez, cez, dez;
REAL aexbey, bexaey, bexcey, cexbey, cexdey, dexcey, dexaey, aexdey;
REAL aexcey, cexaey, bexdey, dexbey;
REAL alift, blift, clift, dlift;
REAL ab, bc, cd, da, ac, bd;
REAL abc, bcd, cda, dab;
REAL aezplus, bezplus, cezplus, dezplus;
REAL aexbeyplus, bexaeyplus, bexceyplus, cexbeyplus;
REAL cexdeyplus, dexceyplus, dexaeyplus, aexdeyplus;
REAL aexceyplus, cexaeyplus, bexdeyplus, dexbeyplus;
REAL det;
REAL permanent, errbound;
aex = pa[0] - pe[0];
bex = pb[0] - pe[0];
cex = pc[0] - pe[0];
dex = pd[0] - pe[0];
aey = pa[1] - pe[1];
bey = pb[1] - pe[1];
cey = pc[1] - pe[1];
dey = pd[1] - pe[1];
aez = pa[2] - pe[2];
bez = pb[2] - pe[2];
cez = pc[2] - pe[2];
dez = pd[2] - pe[2];
aexbey = aex * bey;
bexaey = bex * aey;
ab = aexbey - bexaey;
bexcey = bex * cey;
cexbey = cex * bey;
bc = bexcey - cexbey;
cexdey = cex * dey;
dexcey = dex * cey;
cd = cexdey - dexcey;
dexaey = dex * aey;
aexdey = aex * dey;
da = dexaey - aexdey;
aexcey = aex * cey;
cexaey = cex * aey;
ac = aexcey - cexaey;
bexdey = bex * dey;
dexbey = dex * bey;
bd = bexdey - dexbey;
abc = aez * bc - bez * ac + cez * ab;
bcd = bez * cd - cez * bd + dez * bc;
cda = cez * da + dez * ac + aez * cd;
dab = dez * ab + aez * bd + bez * da;
alift = aex * aex + aey * aey + aez * aez;
blift = bex * bex + bey * bey + bez * bez;
clift = cex * cex + cey * cey + cez * cez;
dlift = dex * dex + dey * dey + dez * dez;
det = (dlift * abc - clift * dab) + (blift * cda - alift * bcd);
aezplus = Absolute(aez);
bezplus = Absolute(bez);
cezplus = Absolute(cez);
dezplus = Absolute(dez);
aexbeyplus = Absolute(aexbey);
bexaeyplus = Absolute(bexaey);
bexceyplus = Absolute(bexcey);
cexbeyplus = Absolute(cexbey);
cexdeyplus = Absolute(cexdey);
dexceyplus = Absolute(dexcey);
dexaeyplus = Absolute(dexaey);
aexdeyplus = Absolute(aexdey);
aexceyplus = Absolute(aexcey);
cexaeyplus = Absolute(cexaey);
bexdeyplus = Absolute(bexdey);
dexbeyplus = Absolute(dexbey);
permanent = ((cexdeyplus + dexceyplus) * bezplus
+ (dexbeyplus + bexdeyplus) * cezplus
+ (bexceyplus + cexbeyplus) * dezplus)
* alift
+ ((dexaeyplus + aexdeyplus) * cezplus
+ (aexceyplus + cexaeyplus) * dezplus
+ (cexdeyplus + dexceyplus) * aezplus)
* blift
+ ((aexbeyplus + bexaeyplus) * dezplus
+ (bexdeyplus + dexbeyplus) * aezplus
+ (dexaeyplus + aexdeyplus) * bezplus)
* clift
+ ((bexceyplus + cexbeyplus) * aezplus
+ (cexaeyplus + aexceyplus) * bezplus
+ (aexbeyplus + bexaeyplus) * cezplus)
* dlift;
errbound = isperrboundA * permanent;
if ((det > errbound) || (-det > errbound)) {
return det;
}
return 0;
//return insphereadapt(pa, pb, pc, pd, pe, permanent);
}
```

And here’s the code that matters at the very end of it :

```
if ((det > errbound) || (-det > errbound)) {
return det;
}
return 0;
//return insphereadapt(pa, pb, pc, pd, pe, permanent);
```

Returning insphereadapt() is what crashes my code. Using return 0 actually makes it run! I think what’s happening is, I have too many function calls so the call stack is overflowed or is just simply not large enough. Because it’s all statically allocated, the size is known at compilation time so it would automatically give a failure.

I think this just means that if my original insphere() result isn’t within error bounds, I need to call all the other functions separately which is a small modification, to say the least. It’s easier than writing my own robust routines lol.