Font Importing Troubles in my Program: Crashes in Release Version in Visual Studio

Hello! I’ve been working on a DearImGUI project of mine since about 2017, based off of the OpenGL3 version of the example code. Only this year I’ve been testing my program in a release format, but that appears to reveal a serious problem.

In my pursuit to improve visibility, I have decided to use Inconsolata as my font of choice, as it was recommended in the Readme.

I have added the font in Main.cpp by entering the following, based on the loading font tips above it, and before the rest of the main calls NewFrame():
“io.Fonts->AddFontFromFileTTF(”…/…/misc/fonts/Inconsolata-Regular.ttf", 17.2f);"
(I also disabled the loading of the Default font, as that would prevent Inconsolata from showing up otherwise. I have not used Font Push or Pop.)

While this font change functions perfectly fine in the debug version of the project in Visual Studio, when compiling the project for release, and attempting to launch the executable, it spits out an error, specifically, the following:
“Assertion Failed: 0 file …\imgui_draw.cpp, line 1549.”
On further study of that error location it appears that this is a NULL error in the function for AddFontFromFileTTF, the same function in which I had attempted to import the font from.
This error occurs even if I enable the Default Font, and attempt to add the Inconsolata font at the same time.

My latest release build, when disabling the font, otherwise functions.

I understand, as shown in the readme regarding fonts, that there is some sort of process using binary_to_compressed_c.cpp which adds a specified font to the application’s library, but I am unsure how to use the function properly, let alone run it using Windows PowerShell or a regional equivalent on my Windows Machine. I’m overall more familiar compiling code on a Linux VM with GCC than creating some sort of exclusive VS project that runs that .cpp file.

I had seen that the readme also referenced a precompiled version of binary_to_compressed_c.cpp within an executable somewhere in the repository, but I have not found out where that might be in the first place. That would seem to be my best option overall.

Any help would be appreciated, thanks!

(1) This is a relative path and your startup/working directory is probably different between your Debug and your Release project options, so the path becomes incorrect. This is your main issue.

(2) You can build the .cpp file into an exe with visual studio’s command line tool by using cl.exe binary_to_compressed_c.cpp as documented in the file itself. You need to run one of the vcvars*.bat file from your visual studio folder to make the compiler accessible in the command-line.

(3) If you look at the page linked to and search for “binary” you’ll find the binary package.

I’m sorry for the late reply, but I’m still getting the same error in my attempt to use binary_to_compressed_c.exe.

Here’s what I have entered into VS2017 command prompt. I’ve got a feeling that I’ve entered the parameters regarding loading Inconsolata incorrectly, but I’m certain that I have managed to compile binary_to_compressed_c.cpp correctly. I had attempted typing in the commands exactly as shown in the readme’s, then, recompiled both the debug and release versions. After that, I launched the compiled release version by itself. The same error still occurred.

I have not yet made any more edits to the main.cpp, just to be sure.

Can I get some help with getting those fonts imported? thank you for you help so far!

You aren’t typing the command as in the readme nor you are reading the instruction explicitely written on the command-line: you forgot to specify a symbol/variable name to use.

I’m really sorry that I’m still quite lost with getting this font embedded in my source code. I believe it may be best that I just attempt to show the portions of readmes that I am referencing in my attempts to put things together.

From Line 167-169 of the readme within the examples\misc\fonts folder.

Then load the font with:
ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels, …);

I believe that this line may be the one necessary to load Inconsolata once binary_to_compressed finishes its work and outputs the content I need. I don’t exactly know what that data would look like, so I’m quite worried that I may enter the wrong parameters in that function in my main.cpp, with the exception of pixel size.

From binary_to_compressed_c.cpp in lines 15-18:

// Usage:
// binary_to_compressed_c.exe [-base85] [-nocompress]
// Usage example:
// # binary_to_compressed_c.exe myfont.ttf MyFont > myfont.cpp

I had attempted to run the usage line above (minus the # of course) in Developer Command Prompt for VS2017, replacing the parameters with the following:

binary_to_compressed_c.exe Inconsolata-Regular.ttf inCon_fontTest > Inconsolata-Regular.cpp

I’m unsure where the symbol name would show up later, but I believe that it may be referenced in the font loading or building process later.

This above command results. in a blank .cpp file as an output. Reducing the amount of arguments manually fills the .cpp file with the built in syntax error, which is a tell that at least it can output something if I manage to put this thing together the right way.

I sincerely apologize if I seem to be bumbling through this. I’m getting started and at this point I feel that I’ve got nowhere else to go for help in this. thank you.

If I run
binary_to_compressed_c.exe Inconsolata-Regular.ttf inCon_fontTest > Inconsolata-Regular.cpp

I get a Inconsolata-Regular.cpp file of about 198 KB with a large table:

I have just noticed one particular case where binary_to_compressed_c.exe doesn’t display anything: if it fails to open or read the input file. So I would say maybe there’s no file called “Inconsolata-Regular.ttf” in your current folder.

I have updated binary_to_compressed_c in master to display an error if it can’t open or read the file.

I believe that I’m on the Home Stretch thanks to your help so far. Using your syntax, I now have a populated Inconsolata-Regular.cpp. Now, I’m trying to get the font loaded within the main. Unfortunately, it’s now crashing in a new location while It’s trying to load the font.

I’m using this line from the readme to try and call it in my main.

ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(“Inconsolata-Regular.cpp”,63718 ,17.2f );

The Compressed Size variable is referenced from the unsigned int in the Inconoslata-Regular.cpp file that was generate from the compression executable.

Looking through where exactly the program popped up an assertion, was in imgui_draw.cpp in line 1484:

IM_ASSERT(font_cfg->FontData != NULL && font_cfg->FontDataSize > 0);

I’ve got a feeling that this error stems from an improper importation of the font data size. Perhaps the actual value is not written in the generated .cpp file? I’ve also made sure that the generated .cpp file is in its needed location. Strangely enough, mis-naming the referenced file in the function call causes the same error to occur.

I really appreciate your help, and I’d love to finally get this lovely font into my build. just a little longer!

You have to #include the .cpp file from another .cpp file and call AddFontFromMemoryCompressedTTF with the symbol and size defined in that file.

I am really sorry for the late reply, but I got it up and running in my example Program! Here’s the specific line that I had used lo load it, while also commenting out the loading of the default font.

ImFont* Inconsolata = io.Fonts->AddFontFromMemoryCompressedTTF(inCon_fontTest_compressed_data, inCon_fontTest_compressed_size, 17.2f);

I sincerely thank you for being patient with all of my problems, and I hope that this is a digital paper trail for anyone else that needs help to get their font importation off the ground!
If there was any way to list this as a solved problem, I’d like to list this thread as such. thanks!

1 Like