The program worked fine until I turned it into a function and added it in a menu to a larger program.
The user clicks on the wordsearch builder, the program closes and returns to a menu. The user clicks on the wordsearch builder a second time and the program crashes.
With error:
"Assertion failed: font, file allegro-5.0.x\addons\font\text.c line 198"
The problem is when I run my word-search builder for the second time it crashes when it tries to display the fonts.
My program is really long so here is the basic code snippits I'm trying to find the bug in.
This indicates that either your font pointer is null or your const char* format is null.
My guess is that "cour.ttf" is not located in the folder that you're running your program from. You need to check the return results of ALL al_load commands to ensure you're loading your files properly.
However, it's much safer to specify full paths to the files you want to load rather than just using filenames. You can use ALLEGRO_PATH objects to accomplish this.
In your case:
1. Make a pointer to an ALLEGRO_PATH object.
2. Call al_get_standard_path() to get the path which leads to where your font is installed.
3. Use al_append_path_component() to append any additional folder names as needed. (IE: If your fonts are stored in a folder called "Fonts".)
4. Set the filename to load using al_set_path_filename().
5. When calling al_load_font(), in place of your filename, use al_path_cstr().
6. Call al_destroy_path() on your ALLEGRO_PATH object to clear it from memory when you're done with it, or if you intend to call al_get_standard_path() on it again.
This may seem like a ton of work, but it pretty much guarantees that the file you want to load will be loaded properly on virtually any user's system. You can read up the details of these functions and how to use them in the Allegro Manual. (Note that al_get_standard_path() is a "System Routine".)
Thank you for your help it narrowed down the bug search. But I am still having a problem when the function loads for a *second* time during the program. The font pointer comes out null despite everything seeming OK.
I capture the null pointer with error code and the function exits returning -1. With this in console window: "Error loading font24."
I don't understand where the memory leak is coming from.
Here is the code snippets:
Use ALLEGRO_NATIVE_PATH_SEP in your call to al_path_cstr() instead of "/". It's safer and more portable and may be the source of your problems.
Beyond that, the only other thing I can suggest is to make sure "cour.ttf" is located in the same place as your executable file and to make sure you actually run your program from the EXE itself, not from any menu options in the C program you're using. If you are using the menu options, you need to be absolutely sure that it's running your executable from the same place the EXE is actually stored in.
Thank you for the tips Kris.
My program has been improved with error tracking code and the file pathing recommendations.
I resolved the issue, it was simple and probably independent of your suggestions. But I don't know exactly why it worked.
*al_load_font* was substituted with *al_load_ttf_font*
Now the program can initialize from the header file without complaints.
That bug was frustrating. For some reason al_load_ttf_font works better??
Here is the final code snippit:
In all honesty, I make my own bitmapped fonts for my games due to the licensing issues with distributing True-Type fonts and because it helps to give my software its own identity. So as far as TTF loading goes, I have next to no experience. I don't know what bugs or nuances there are as a result of trying to load them in A5.