# SDL\_TTF error after Dialog to browse file created

**URL:** <https://discourse.libsdl.org/t/sdl-ttf-error-after-dialog-to-browse-file-created/25171>\
**Category:** SDL Development\
**Created:** [October 18, 2018, 10:19am UTC](https://discourse.libsdl.org/t/sdl-ttf-error-after-dialog-to-browse-file-created/25171 "2018-10-18T10:19:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debson](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@Debson](https://discourse.libsdl.org/u/Debson)\
**Post date:** [October 18, 2018, 10:19am UTC](https://discourse.libsdl.org/t/sdl-ttf-error-after-dialog-to-browse-file-created/25171/1 "2018-10-18T10:19:31Z")

</div>

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();
}
```

---

<div class="post-metadata">

**Author:** ![Mason\_Wheeler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/b9bd4f/32.png) [@Mason\_Wheeler](https://discourse.libsdl.org/u/Mason_Wheeler)\
**Post date:** [October 18, 2018, 10:43am UTC](https://discourse.libsdl.org/t/sdl-ttf-error-after-dialog-to-browse-file-created/25171/2 "2018-10-18T10:43:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Debson](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@Debson](https://discourse.libsdl.org/u/Debson)\
**Post date:** [October 18, 2018, 10:57am UTC](https://discourse.libsdl.org/t/sdl-ttf-error-after-dialog-to-browse-file-created/25171/3 "2018-10-18T10:57:16Z")

</div>

“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.

---

<div class="post-metadata">

**Author:** ![Mason\_Wheeler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/b9bd4f/32.png) [@Mason\_Wheeler](https://discourse.libsdl.org/u/Mason_Wheeler)\
**Post date:** [October 18, 2018, 11:11am UTC](https://discourse.libsdl.org/t/sdl-ttf-error-after-dialog-to-browse-file-created/25171/4 "2018-10-18T11:11:14Z")

</div>

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](https://en.wikipedia.org/wiki/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!
