SDL_TTF error after Dialog to browse file created

Hi,

After creating a windows file browse dialog and choosing any of the files in browse dialog TTF crashes and is not able to open the font.
What’s more interesting, when I do the same but with folder browse dialog, it works as it should.
TTF_GetError() gives me an error, that cannot open that font.
I tried to run this function on main thread and different thread, and it’s the same.

void FileBrowser::OpenFileBrowser()
{
	std::string filenameBuffer;
	OPENFILENAMEA ofn;

	convertedFilenames.erase();

	filenameBuffer.resize(MAX_FILEPATH_BUFFER_SIZE);

	ZeroMemory(&filenameBuffer[0], filenameBuffer.size());
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = Window::GetHWNDWindow();
	ofn.lpstrFilter = "All Files\0*.*\0\0";// filterC;
	ofn.lpstrFile = &filenameBuffer[0];
	ofn.nMaxFile = MAX_FILEPATH_BUFFER_SIZE;
	ofn.lpstrTitle = "Open";
	ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;


	if (GetOpenFileNameA(&ofn) == FALSE)
		convertedFilenames = "";

        /* Font after choosing any of the files won't open, it will be NULL. When dialog is only opened
           and canceled, font is opened properly. Only causes errors when file is chosen.
        */
        TTF_Font* font = TTF_OpenFont(Strings::_FONT_PATH.c_str(), 14);
		TTF_CloseFont(font);

	
	filenameBuffer.erase();
}

What’s the exact text of the error you’re getting?

1 Like

“Couldn’t open assets/font/Times New Roman.ttf”
Changed the font file path to an absolute path and now it’s working… I can’t figure out something with my program, I write post on this forum and surprisingly new ideas come up to my mind… Sorry for bothering, but at that point I was out of ideas.

Yeah, we’ve all been there. That’s a common enough thing that it has its own name and a Wikipedia article:

Rubber duck debugging

Rubber duck debugging

Many programmers have had the experience of explaining a problem to someone else, possibly even to someone who k…

Happy to help!