私のコードでかなり奇妙なクラッシュが発生しましたが、その原因がわかりません。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 */
ここで何か間違っていますか?これはライブラリの問題ですか、それとも私の OS の問題ですか? 私が見逃した PhysFS のビルドステップに何かありましたか?
編集: PHYSFS_init() の戻り値を間違って読んだことに気付きましたが、PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())
「エラーなし」を返すのでさらに混乱しています。ここで何が起こっているのでしょうか?