Skip to content

Fix (possible) segfaults throughout code in kernel calls

Josh Borrow requested to merge fix_black_hole_segfault_crash into master

Throughout the code there was the following pattern used:

/* Get r and 1/r. */
// r2 = 0, so r_inv is inf
const float r_inv = 1.0f / sqrtf(r2);
// 0 / inf = - nan
const float r = r2 * r_inv;
// - nan again
const float ui = r * hi_inv;
// branch for - nan? segfault, as 0 < ui < kernel_gamma
kernel_deval(ui, &wi, &wi_dx);

causing segfaults in the kernel_deval if r2=0.0. This PR addresses this issue throughout (apart from in the gravity, where I have left it unchecked).

It also adds a random offset to the black holes when they are repositioned, so that they are never repositioned on top of gas particles (@dc-bahe1).

Merge request reports