On windows i want to be able to load a level for my game trough the a explorer window. I use the this api: https://learn.microsoft.com/en-us/windows/win32/api/commdlg/nf-commdlg-getopenfilenamea
I'm able to open the explorer, get the filename and load the level but sometimes the programm just crashes with an access violation somewhere in my d3d11 render pipeline out of nowhere after i close the explorer window (even if i don't select a file)...
I really don't understand what is going, so any kind of help or suggestion is welcome. I really would like to give you more information but i really don't have a clue what this is causing.
This is standard code from an example on the official documentation. The only thing i changed is that the hwndOwnder is set to NULL because otherwise the explorer window would not open, maybe that causes problems?
Here is the code for the API:
// Initialize OPENFILENAME
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szFile;
// Set lpstrFile to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; // Display the Open dialog box.
hf = CreateFile(ofn.lpstrFile, GENERIC_READ, 0, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);
...........file gets loaded