我在我的代码中遇到了一个相当奇怪的崩溃,我不确定是什么原因造成的。我试图在我的 c++ 代码中使用 PhysFS。下面的代码是类的一部分,Visual Studio 2017 告诉我崩溃出现在 中PHYSFS_mount()
,随后出现在 中,据EnterCriticalSection()
我了解,这与互斥锁有关。现在根据我的理解,这应该是正确的(请注意,主要调用initArchives()
首先)
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(); });
}
崩溃显然出现在这里
int __PHYSFS_platformGrabMutex(void *mutex)
{
EnterCriticalSection((LPCRITICAL_SECTION) mutex); // <-- here
return 1;
} /* __PHYSFS_platformGrabMutex */
我在这里做错了吗?这是图书馆的问题还是我的操作系统的问题?我错过了 PhysFS 的构建步骤中的某些内容吗?
编辑:我注意到我读错了 PHYSFS_init() 的返回值,但是现在我更加困惑,因为PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())
返回“没有错误”,这是怎么回事?