flann-lib / flann

Fast Library for Approximate Nearest Neighbors
http://people.cs.ubc.ca/~mariusm/flann
Other
2.22k stars 647 forks source link

save_to_file runtime error #462

Open morejiik opened 4 years ago

morejiik commented 4 years ago

Hi all, I'm using flann::save_tofile() to save a data matrix created with the aid of Point Cloud Library 1.10.0. The program works fine with data matrix flann::Matrix:

 rows: 37
 cols: 308
 stride: 1232
 type: FLANN_FLOAT32 (8)

As soon as the rows increase above 37 elements I get a runtime error. The error is: Unhandled exception at 0x00007FFEEAC9A799 in vfh_training.exe: Microsoft C++ exception: flann::FLANNException at memory location 0x00000029E72FF8E0. occurred

The error is generated after compiling and running the following (sample) code:

#define H5_BUILT_AS_DYNAMIC_LIB

#include <flann/flann.h>    
#include <flann/io/hdf5.h>

int main()
{

    int rows{ 38 };
    int cols{ 308 };
    //FLANN data
    flann::Matrix<float> data(new float[rows * cols], rows, cols);
    for (std::size_t i = 0; i < data.rows; ++i)
        for (std::size_t j = 0; j < data.cols; ++j)
            data[i][j] = i*j;

    // Save data to disk
    flann::save_to_file(data, "flann_data", "training_data");
    std::cout<<"Data saved to disk.\n";

}

Configuration: Platform: Win 10 x64 FLANN version: (?) integrated as 3rd Party tool of PCL 1.10.0 HDF5: 1.12.0 IDE: Visual Studio 16.6.2 CMake: 3.16.4

morejiik commented 4 years ago

Update: I've found the problem. If you have an already existing file (in this case "flann_data") on disk, in the moment that you try to overwrite it with data of bigger size (i.e. with more elements in the matrix) it throws an exception. Everything works fine if the size is the same or smaller than the previous saving. It means that I've to check the existence of the file before saving and delete it if exists.

I hope this helps someone.

In any case, this a strange behaviour and should be considered as an issue.