Setting font-size with Heaps crashes the app

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)

JS stack trace:

Uncaught TypeError: this.font is null
    set_font file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:17620
    validateStyle file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:57862
    validateStyle file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:58002
    validateComponentInternal file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:65047
    validateComponent file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:65021
    validateComponentInternal file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:2379
    validateComponent file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:2301
    process file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:75356
    t file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:74368
    update file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:58034
    update file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:55063
    onHeapsUpdate file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:55187
    update file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:56801
    mainLoop file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:56764
    setup file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:56734
    loadAssets file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:56754
    setup file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:56730
    onCreate file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:24569
    onLoad file:///home/nixbody/HeapsUI/build/heaps/js/Main.js:36912

main-view.xml:

<vbox style="padding: 5px;">
    <style>
        * {
            font-size: 31px;
        }
    </style>
    <vbox>
        <button text="Red" id="button1" style="color: red;" />
        <button text="Green" id="button2" style="color: green;" />
        <button text="Blue" onclick="this.text='Thanks!'" style="color: blue;" />
        <textfield />
    </vbox>    
</vbox>

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.

Howdy,

So changing font sizes is certainly supported (in haxeui-heaps also), have up updated recently? Is this the same line you have: https://github.com/haxeui/haxeui-heaps/blob/master/haxe/ui/backend/TextDisplayImpl.hx#L73

I changed something here quite recently. I wonder if that is causing the issue. Any chance you have a test project for me to be able to play with?

Cheers,
Ian

1 Like

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?

is there any online service your prefer for me to upload the test project?

I dont mind, you can also email it to me if you want: ianharrigan@hotmail.com

Cheers,
Ian

All right, here’s the link to the test project: HeapsUI.zip

The project is in a state that causes it to crash but if you set font-size to 32px (original size) it starts to work normally.

Thank you again and have a good day.

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 :slight_smile:

image

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) {

Let me know if that all works now.

Cheers,
Ian

1 Like

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 :frowning:
First:

SIGNAL 11
String.charCodeAt(/usr/share/haxe/std/hl/_std/String.hx:54)
h2d.Text.splitRawText(h2d/Text.hx:330)
h2d.Text.splitText(h2d/Text.hx:304)
h2d.TextInput.getAllLines(h2d/TextInput.hx:368)
h2d.TextInput.sync(h2d/TextInput.hx:480)
h2d.Object.sync(h2d/Object.hx:610)
haxe.ui.backend.ComponentImpl.sync(haxe/ui/backend/ComponentImpl.hx:630)
h2d.Object.sync(h2d/Object.hx:610)
haxe.ui.backend.ComponentImpl.sync(haxe/ui/backend/ComponentImpl.hx:630)
h2d.Object.sync(h2d/Object.hx:610)
haxe.ui.backend.ComponentImpl.sync(haxe/ui/backend/ComponentImpl.hx:630)
h2d.Object.sync(h2d/Object.hx:610)
h2d.Scene.sync(h2d/Scene.hx:795)
h2d.Scene.render(h2d/Scene.hx:782)
hxd.App.render(hxd/App.hx:129)
h3d.Engine.render(h3d/Engine.hx:414)
hxd.App.mainLoop(hxd/App.hx:198)
hxd.$System.mainLoop(hxd/System.hl.hx:76)
hxd.$System.runMainLoop(hxd/System.hl.hx:159)
haxe.$Timer.~delay.0(/usr/share/haxe/std/haxe/Timer.hx:144)
haxe.$Timer.~__constructor__.0(/usr/share/haxe/std/haxe/Timer.hx:76)
sys.thread.EventLoop.loop(/usr/share/haxe/std/sys/thread/EventLoop.hx:177)
sys.thread._Thread.$Thread_Impl_.processEvents(/usr/share/haxe/std/hl/_std/sys/thread/Thread.hx:62)
.init(?:1)
Segmentation fault (core dumped)

Second:

SIGNAL 11
$String.__add__(/usr/share/haxe/std/hl/_std/String.hx:254)
haxe.ui.styles.Parser.parse(haxe/ui/styles/Parser.hx:47)
haxe.ui.styles.StyleSheet.parse(haxe/ui/styles/StyleSheet.hx:107)
haxe.ui.styles.CompositeStyleSheet.parse(haxe/ui/styles/CompositeStyleSheet.hx:83)
haxe.ui.themes.ThemeManager.addStyleString(haxe/ui/themes/ThemeManager.hx:161)
haxe.ui.themes.ThemeManager.applyResource(haxe/ui/themes/ThemeManager.hx:152)
haxe.ui.themes.ThemeManager.applyTheme(haxe/ui/themes/ThemeManager.hx:117)
haxe.ui.$Toolkit.init(haxe/ui/Toolkit.hx:77)
haxe.ui.HaxeUIApp.init(haxe/ui/HaxeUIApp.hx:40)
haxe.ui.HaxeUIApp.ready(haxe/ui/HaxeUIApp.hx:24)
$Main.main(Main.hx:10)
.init(?:1)
Segmentation fault (core dumped)

I dont think so - even the SDFFonts.register stuff is pretty new

Thanks! :blush:

Can you let me know how i might be able to reproduce them? I can then see if they are HL or haxeui… and either fix or workaround them (if possible).

Cheers,
Ian

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.

Edit: Could be related to this issue: SIGNAL 11 Segmentation fault · Issue #579 · HaxeFoundation/hashlink · GitHub

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.

Have a nice weekend.