-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using multiple merged fonts -> crash on ClearFonts() ? #544
Comments
Well, I merged all into one big texture now, that circumvents my problem. |
I would like to look at this. It isn't clear what you were doing, could you elaborate? Were you creating multiple ImFontAtlas? |
I did not change any imgui code in terms of ImFontAtlas, so no, I did not create multiple instances of it. // 2nd Font // 3rd Font // 4th Font I do have to say that it was not really obvious how to get where I wanted, so I may have done it the wrong way. But this way, the Fonts[] would hold the pointer to the default English language multiple times which then crashed on ClearFonts() ... but I am not 100% sure why this happened.... |
Calling AddFontDefault() multiple times shouldn't be a problem. |
By the way what you were doing sounds right to me (it is just unfortunately a little tedious to fill all those fields). So it isn't clear what you have changed that have fixed the problem for you:
ImFontAtlas is always one big texture, that's the entire point of the atlas. So if you hadn't created different font atlas before then that statement doesn't appear to make sense. There's no such thing as It would be good to have more information about your program state/from your debugger at the time of calling ClearFonts(). |
Ohh, maybe this was the problem: Since ImGui is using a vector for the Fonts and the "switch language" was always switching the entries in that vector, I never knew which entry belonged to which language. So I added actually 5 languages: this way I could switch the language by just moving the one I wanted to show into place 0. // 1st Font // 2nd Font... ... Could it be because of me using the SAME AddFontFromFileTTF file twice ? |
I had trouble with a huge texture font before on smaller GPUs (Onboard stuff), that's why I came up with that idea to split them into 4 textures. But it seems you changed the default max texture size in one of the recent commits and now it seems to work fine with one big texture :) , that is what I meant with "I solved it by merging all into one texture" |
What do you mean by "moving the one I wanted to show into place 0" ? If you copy around the pointers in that array ImGui will have duplicate pointers and of course it'll crash when attempting to free the structure. You probably don't want to mess up with that array. You can change your font by using ImGui::PushFont(my_font); Just grab the pointer return from AddFont() functions and use that instead of messing up with indices.
But none of your code is splitting anything into 4 textures. You are creating 4 fonts but it's still and always 1 texture. You cannot create multiple textures unless you create multiple ImFontAtlas which you haven't done. ( Ideally we'd need to work on a dynamic atlas to solve this issues with Chinese language, but allocating multiple days of work on ImGui is difficult. In the meanwhile compute your ranges based on your data or reduce oversampling ) |
Yes, that copying around was indeed the problem... -.-... I'm sorry for wasting your time... |
No worry! At least I wanted to make sure there's wasn't a crashing bug in the library. I suppose when everything is public it is easy to make that sort of mistake. Thanks for helping to clarify! I have added a comment which might help other people. |
Hey,
I am not sure if this is just me using the DefaultFont wrong or if this is a bug. I have 4 Language files, 1 which is the default Latin one, being loaded from memory, and 3 other ones which are loaded from a seperate file. Since these 4 languages need the default Latin one as well, I created 4 languages which each are a merged Latin + other language - Font.
It all works fine, I have 4 separate languages to choose from and I can switch without problems in between.
Now the crash occurs in the Dtor which calls ClearFonts(), where it iterates through the allocated Fonts and due to the Default Latin language being the same memory area, it obviously rashes on the 2nd iteration.
My probably wrong way to get 4 merged language files (?)
If that is the wrong way to do what I want, any advice how to load multiple languages which each have the default one merged into them ?
The text was updated successfully, but these errors were encountered: