template <>
float String_v1<float>::force_calc (element left, element center, float l){
float d_l=-10;
float h = (center.h-left.h);
d_l = (float)((float)(h*h)+(float)(l*l));
d_l = std::sqrt(d_l)-l;
float f = d_l*left.k;
if(center.h>left.h)
f=-f;
return f;
}
Add func for exclude NaN and infinities. Still crashes
inline float inf_clamp(float x){
return std::isfinite(x) ? x : 0.f; }
template <>
float String_v1<float>::force_calc (element left, element center, float l){
float d_l=-10;
float h = (center.h-left.h);
d_l = (float)((float)(h*h)+(float)(l*l));
d_l = inf_clamp(d_l);
d_l = std::sqrt(d_l)-l;
float f = d_l*left.k;
if(center.h>left.h)
f=-f;
return inf_clamp(f);
}
I noticed strange thing. If I add my module in new patch, VCV rack crashes and log.txt do not have stack trace.
If patch with my module loads instantly after start VCV rack, log.txt does have stack trace.
You keep saying that Rack crashes when you add certain code, but what are you able to do to make Rack not crash?
Debugging is not a matter of absolute results but a matter of delta-results, or changes to behavior given a controlled change to input.
Can you rule out the result being probabilistic by verifying that the stack trace is the same across many similar experiments?
My guess: At some earlier point, a function returned a pointer to a variable on the stack. Later, when you call sqrt(), the sqrt() function writes to that stack space, so the variable is no longer valid. If you don’t call sqrt(), the variable doesn’t get stepped on (yet).