kahowell/physfs-cpp

Exception handling doesn't work

SirNerdBear opened this issue · 2 comments

Given code like this where the file doesn't exist:

try {
    PhysFS::ifstream file ("filename.txt");
} catch (std::invalid_argument e) {
    //do something here
}

A bad access error will crash the program.

If I remove the exception handling, then it correctly shows the unhanded exception of:

throw std::invalid_argument("file not found: " + std::string(filename));

I suspect the bad access error to be because you haven't initialized the library properly. I more-or-less ported the same semantics as the physicsfs lib, so it's required to call PhysFS::init first... That being said, I'd totally like to make it easier to use by not requiring this. Pull request welcome 😄 I added unit testing to the project (requiring cppunit), so it should be easy to dev this enhancement.

If that is not what's causing the issue, a test case would be much appreciated.

Had the same problem, and I did init PhysFS with argv[0] from SDL's main.