Im experiencing a rather weird crash in my code and im unsure as to what causes it. Im trying to use PhysFS in my c++ code. the code below is part of a class and Visual Studio 2017 tells me that the crash appears in PHYSFS_mount()
and subsequently in EnterCriticalSection()
, which to my understanding has something to do with mutexes. Now from my understanding this should be correct (Note that the main calls initArchives()
first)
physfs_initialized = false;
...
void scope::parse_archive(const std::string& archive_path, const std::string& path_in_archive)
{
assert(physfs_initialized);
m_archivePath = archive_path;
m_relativeArchivePath = path_in_archive.substr(1);
//fsx = std::filesystem or std::expiremental::filesystem whatever floats your boat
if(exists(fsx::path(archive_path))) return;
if(!PHYSFS_mount(m_archivePath.c_str(),"",0)) return;
const auto file = PHYSFS_openRead(m_relativeArchivePath.c_str());
if(file) m_isValid = true;
PHYSFS_close(file);
PHYSFS_unmount(m_archivePath.c_str());
}
...
void initArchives(char ** argv)
{
if (!PHYSFS_init(argv[0])) physfs_initialized = true;
//a bit of ugly syntax because of the need to consume the return type
atexit([]() {PHYSFS_deinit(); });
}
The crash apparently appears here
int __PHYSFS_platformGrabMutex(void *mutex)
{
EnterCriticalSection((LPCRITICAL_SECTION) mutex); // <-- here
return 1;
} /* __PHYSFS_platformGrabMutex */
Am I doing something wrong here ? Is this a problem of the library or even with my OS ? Was there something in the buildstep of PhysFS that I missed ?
Edit: I noticed that I read the return value of PHYSFS_init() wrong, however now I'm even more confused as PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())
returns "no error", what is going on here ?
Apparently there is a bug in PhysFS regarding Windows 10. That prohibits the correct execution of PHYSFS_init() changing line 578 of phsyfs_platform_windows.c to
rc = pGetDir(accessToken, NULL, &psize);
and a recompile of the library fixed the problem for me :/
https://hg.icculus.org/icculus/physfs/rev/ece6769c0676
https://discourse.libsdl.org/t/resolved-physfs-exception-thrown/25697/11