I’m using the latest Git versions of haxeui-core, haxeui-heaps, heaps and hashlink. It dosen’t matter if I use JS or HashLink, both variants crash when I try to set a different font size than the original one. I’ve tried the default font and a custom SDF font created from DejaVu Sans using Hiero. Setting font-size to a different size freezes or crashes the application. When the size differs only slightly from original (e. g. 12px vs 13px) then it may not crash but the text is cutoff and distorted.
HashLink stack trace:
Null access .size
Called from h2d.TextInput.set_font (h2d/TextInput.hx line 442)
Called from haxe.ui.backend.TextDisplayImpl.validateStyle (haxe/ui/backend/TextDisplayImpl.hx line 73)
Called from haxe.ui.backend.TextInputImpl.validateStyle (haxe/ui/backend/TextInputImpl.hx line 51)
Called from haxe.ui.core.TextInput.validateComponentInternal (haxe/ui/core/TextInput.hx line 374)
Called from haxe.ui.core.TextInput.validateComponent (haxe/ui/core/TextInput.hx line 352)
Called from haxe.ui.core.ComponentValidation.validateComponentInternal (haxe/ui/core/ComponentValidation.hx line 273)
Called from haxe.ui.core.ComponentValidation.validateComponent (haxe/ui/core/ComponentValidation.hx line 182)
Called from haxe.ui.validation.ValidationManager.process (haxe/ui/validation/ValidationManager.hx line 140)
Called from haxe.ui.util.$Timer.~delay.1 (haxe/ui/util/Timer.hx line 10)
Called from haxe.ui.backend.$TimerImpl.update (haxe/ui/backend/TimerImpl.hx line 13)
Called from haxe.ui.backend.$BackendImpl.update (haxe/ui/backend/BackendImpl.hx line 7)
Called from haxe.ui.backend.AppImpl.onHeapsUpdate (haxe/ui/backend/AppImpl.hx line 56)
Called from haxe.ui.backend._AppImpl.HeapsApp.update (haxe/ui/backend/AppImpl.hx line 18)
Called from hxd.App.mainLoop (hxd/App.hx line 193)
Called from hxd.App.~setup.2 (hxd/App.hx line 150)
Called from hxd.App.loadAssets (hxd/App.hx line 176)
Called from hxd.App.setup (hxd/App.hx line 146)
Called from h3d.Engine.onCreate (h3d/Engine.hx line 258)
Called from h3d.impl.GlDriver.~init.0 (h3d/impl/GlDriver.hx line 1617)
Called from haxe.$Timer.~delay.0 (/usr/share/haxe/std/haxe/Timer.hx line 144)
Called from haxe.$Timer.~__constructor__.0 (/usr/share/haxe/std/haxe/Timer.hx line 76)
Called from sys.thread.EventLoop.progress (/usr/share/haxe/std/sys/thread/EventLoop.hx line 140)
Called from hxd.$System.runMainLoop (hxd/System.hl.hx line 153)
Called from haxe.$Timer.~delay.0 (/usr/share/haxe/std/haxe/Timer.hx line 144)
Called from haxe.$Timer.~__constructor__.0 (/usr/share/haxe/std/haxe/Timer.hx line 76)
Called from sys.thread.EventLoop.loop (/usr/share/haxe/std/sys/thread/EventLoop.hx line 177)
Called from sys.thread._Thread.$Thread_Impl_.processEvents (/usr/share/haxe/std/hl/_std/sys/thread/Thread.hx line 62)
Perhaps this isn’t event supported or I’m doing something wrong, I don’t know, but it would be nice to have the ability to use a single custom font with different sizes.
Hello and thank you for your answer, that’s very good to hear. I double-checked and yes, I have the very latest revisions of both haxeui-core and haxeui-heaps (which contains that line #73 with sprite.font = null statement). I’ve also noticed that Toolkit.scale dosen’t scale text, only the components but not the text inside them. I don’t see an option to upload a ZIP file here, is there any online service your prefer for me to upload the test project?
Alright, thats fixed now - i would argue it was actually a bug in heaps (or an inconsistency at least). You can set h2d.Text font to null, but do the same on h2d.TextInput and it will crash. Anyways, ive worked around it now in latest haxeui-heaps
FYI: to get your font to display correctly, i had to “register” it as an SDF with haxeui-heaps:
SDFFonts.register("fonts/font.fnt");
This is because heaps uses fonts very differently depending on if they are bitmap or sdf fonts, and this seemed like the best (only?) approach. Note there are other params you can set when registering it that will control how its renderered:
public static function register(name:String, channel:h2d.Font.SDFChannel = 0, alphaCutoff:Float = 0.5, smoothing:Float = 0.5) {
Wow, that was quick. Thank you so much for the fix, now with the latest version (when I use SDFFonts.register(...)) it seems to work correctly. Are there any other things that needs/should be done to use the Heaps backend correctly? I’ve just started with Heaps so I’m still very new to this.
HaxeUI is like the GUI toolkit I’ve always wanted and so I’m very glad and thankful that you created it.
P. S. I got a couple of segfaults but that may be a bug in HashLink itself, I’m afraid First:
The first one happens sometimes (but pretty often) when I’m just typing in the text field (same project I sent) but right now, unfortunately, I’m unable to replicate it reliably. The second one happens randomly at the startup of the application. I’m running the latest Git revision of HashLink on Linux, maybe on Windows things are more stable.
One last thing, there is a situation when font isn’t scaled properly. If font-size is the same as defaultFontSize then it dosen’t pass this condition: if (currentFontSize != fontSizeValue) (haxeui-heaps/TextDisplayImpl.hx at master · haxeui/haxeui-heaps · GitHub) and font isn’t resized even if Toolkit.scale != 1.