bigg icon indicating copy to clipboard operation
bigg copied to clipboard

Cubes example crashes (SIGSEGV) with no errors if executed from other directories

Open dejaime opened this issue 3 years ago • 0 comments

In the ExampleCubes::initialize function the application builds a relative path to the files (v/f)s_cubes.bin. If your working directory is the same as the application, it works fine, but crashes if you try to execute from any other directory.

How to reproduce:

  1. mkdir build && cd build
  2. cmake .. -DBIGG_EXAMPLES=ON
  3. make
  4. examples/cubes/cubes <-- Crashes with SIGSEGV, no error messages
  5. cd examples/cubes && cubes <-- Works fine

Crash happens on cubes.cpp:78, mProgram = bigg::loadProgram( vsName, fsName );, actually inside of bigg::loadProgram.

Fixing the example so that the file loading works independently from the working directory would be nice. But this still leaves an undesirable behavior for anyone using the bigg framework, as bigg::loadProgram simply crashes without any error output in case the parameters passed to it are invalid. As a user, I can either use exceptions or do something like this (resulting in unnecessary file open/close calls):

std::ifstream tesingVS( vsName, std::ios::binary | std::ios::ate );
std::ifstream tesingFS( fsName, std::ios::binary | std::ios::ate );

if (tesingFS.is_open() && testingVS.is_open()) {
    testingVS.close();
    testingFS.close();
    mProgram = bigg::loadProgram( vsName, fsName );
} else {
    //Return some error or crash out
    std::cerr<<"Failed opening file " << vsName << " or " << fsName << std::endl;
    exit(EXIT_CODE);
}
//Continue

Though I guess I'd be satisfied if the function outputted some "failed to open file" logs to cerr before crashing out.

dejaime avatar Feb 18 '21 18:02 dejaime