physfs-cpp icon indicating copy to clipboard operation
physfs-cpp copied to clipboard

Exception handling doesn't work

Open SirNerdBear opened this issue 10 years ago • 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));

SirNerdBear avatar Jun 23 '15 23:06 SirNerdBear

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 :smile: 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.

kahowell avatar Aug 14 '15 02:08 kahowell

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

radgeRayden avatar Jul 08 '16 18:07 radgeRayden