Closed ruggieroguida closed 4 years ago
This is not a bug of Fiddle. This is a bug in your program.
tmrt4_shading[k] = (1.0 - ground_person_view_factor) * (shading_view_factors_matrix[k * cols_svf + c]) * surroundings_emissivity * pow((273.15 + shading_temperatures_matrix[k * cols_svf + t]), 4);
shading_temperatures_matrix[k * cols_svf + t])
accesses invalid memory. Maybe you should use cols_st
instead of cols_svf
here.
I am using
Ruby Fiddle
to access a C function to perform some heavy calculations. The C function works perfectly well when called directly, but when used viaFiddle
it returns various rows ofnan
s andinf
s in an unpredictable way. The function operates on matrices that are passed as pointers to arrays.I have debugged the C code and everything works fine. I have also saved the various parameters passed to the C function to file to be sure that Fiddle was not passing some weird values, but there is no obvious (at least for me) problem.
Additionally it seems that for 'smaller' matrices this does not happen. Apologies in advance for the code being very long, but this is the only way to exactly reproduce what it is happening. Data for testing is in this file. You can just copy and paste the Ruby and C test data to the code below. I am working on macos Catalina and Ruby 2.2.4 (requirement).
The C code is the following:
and I compile is with
clang -g --extra-warnings utils.c -o utils
.The Ruby code is the following
If you want to test it, first launch
./utils
. It will save a few files on the local folder. Have a look atMRT_MAT.txt
.Now launch the ruby code several times. It will generate the same file, but you will notice that "often" the file will contain random rows with nan and inf. The same data is returned to Ruby and saved in the file
MRT_MAT_RUBY.txt
in the local directory.I am quite familiar with Ruby, but C is not really my strength. It would be great being able to debug the C code when called from Ruby, but I don't really know how to do it.