HaxeUI-kha and native issues with latest verions

Hi!
So, i’ve been updating my Kha stuff to the latest builds, and there’s been some changes under the hood … Kore is gone and has been replaced with Kinc totally now - and haxe has been updated to 4.2

This sounds great, but im having some issues with HaxeUI-kha - native windows versions keep crashing…

Among other things i have the weird error:

G
→ PNG chunk not known

It seems to be caused by some of HaxeUIs resource embedding… Maybe a 4.2 issue…?

(kha html works fine, no issues!)

Hmmm, interesting… ive mainly been checking the html5 version, ill have to make a point to also check window native builds… what version of haxeui are you using?

Cheers,
Ian

Im using the latest haxeui versions from haxelib!
Worked fine before with an earlier version of kha without the Haxe 4.2 updates

Yeah, it seems to be an issue with either kha/kinc/hxcpp/haxe 4.2, been speaking to Rob and have a minimal example (no haxeui) for him to work with:

package;

import haxe.Resource;
import kha.Assets;
import kha.Color;
import kha.Framebuffer;
import kha.Image;
import kha.Scheduler;
import kha.System;

class Main {
    static var imageAsResource:Image = null;
    static var imageFromBytes:Image = null;
    static var imageFromFile:Image = null;
    
	static function update(): Void {
	}

	static function render(frames: Array<Framebuffer>): Void {
		// As we are using only 1 window, grab the first framebuffer
		final fb = frames[0];
		// Now get the `g2` graphics object so we can draw
		final g2 = fb.g2;
		// Start drawing, and clear the framebuffer to `petrol`
		g2.begin(true, Color.fromBytes(255, 255, 255));
        
        if (imageAsResource != null) {
            g2.drawImage(imageAsResource, 10, 10);
        }
        if (imageFromBytes != null) {
            g2.drawImage(imageFromBytes, 150, 10);
        }
        if (imageFromFile != null) {
            g2.drawImage(imageFromFile, 300, 10);
        }
        
		g2.end();
	}

	public static function main() {
		System.start({title: "Project", width: 1024, height: 768}, function (_) {
			Assets.loadEverything(function () {
                
                imageAsResource = Assets.images.get("kha");
                loadFromHaxeResource(false, function() {
                    loadFromFileSystem(true, function() {
                        Scheduler.addTimeTask(function () { update(); }, 0, 1 / 60);
                        System.notifyOnFrames(function (frames) { render(frames); });
                    });
                });
			});
		});
	}
    
    private static function loadFromHaxeResource(perform:Bool, cb:Void->Void) {
        if (perform == false) {
            cb();
            return;
        }
        var bytes = Resource.getBytes("kha.png");
        trace("-----> " + bytes.length);
        Image.fromEncodedBytes(bytes, "png", function(image) {
            imageFromBytes = image;
            cb();
        }, function(error) {
            trace("error: " + error);
            cb();
        });
    }
    
    private static function loadFromFileSystem(perform:Bool, cb:Void->Void) {
        #if !sys
        perform = false;
        #end
        if (perform == false) {
            cb();
            return;
        }
        
        var bytes = sys.io.File.getBytes("C:\\Temp\\kha_image_test\\Assets\\kha.png");
        trace("-----> " + bytes.length);
        Image.fromEncodedBytes(bytes, "png", function(image) {
            imageFromFile = image;
            cb();
        }, function(error) {
            trace("error: " + error);
            cb();
        });
    }
}

Watch this space i guess

Cheers,
Ian

Ah, i talked with him about it yesterday too - you were faster than me setting up a test example :grinning_face_with_smiling_eyes:

1 Like

Issue should be fix in latest kinc - ive verified with and without haxeui and all seems well again

image

Nice catch :slight_smile:

Cheers,
Ian

1 Like

Just wanted you to know while this mostly works fine now - the error still happens from time to time - could it be that if a resource is not found , it crashes?

Is it the same error? Any way to get a reproducible test case? Might be another “kha” thing?

Its the exact same error - but i think this happens if a resource is not found / embedded. Perhaps add a check to see if the resource is valid or something?

Yeah, i guess a check couldnt hurt, but if they happen randomly then i would imagine the resource does exist (otherwise i would expect it to fail every time consistently, no?)

No, its not random - i belive it happens when you try to view a component that uses an images that should be embedded but for some reason isnt (like the png was missing) - So the getResource data is null probably?

OK, right, so yeah, maybe a check would make sense then - additionally, can you isolate what component is causing the issue - would also be nice to fix that too

Cheers,
Ian

Right, ok… It seems to happen at several places.
The image component will cause the crash - or the scrollbars - when they appear the app crashes.
Not sure -why- they arent found … but im pretty sure the crash happens because the embedded resources arent found / are null.

here is the stacktrace:

| |[Inline Frame] FoxEditor.exe!kinc_microsoft_affirm(HRESULT result) Line 38|C++|
|---|---|---|
| |FoxEditor.exe!kinc_g4_texture_init_from_image(kinc_g4_texture * texture, kinc_image * image) Line 94|C++|
| |FoxEditor.exe!kha::Image_obj::initFromEncodedBytes(Array<unsigned char> bytes, String format) Line 118|C++|
| |FoxEditor.exe!kha::Image_obj::fromEncodedBytes(hx::ObjectPtr<haxe::io::Bytes_obj> bytes, String format, Dynamic doneCallback, Dynamic __o_readable, hx::Null<bool>) Line 368|C++|
| |FoxEditor.exe!haxe::ui::backend::AssetsImpl_obj::imageFromBytes(hx::ObjectPtr<haxe::io::Bytes_obj> bytes, Dynamic callback) Line 189|C++|
| |FoxEditor.exe!haxe::ui::backend::AssetsImpl_obj::getImageFromHaxeResource(String resourceId, Dynamic callback) Line 161|C++|
| |FoxEditor.exe!`haxe::ui::ToolkitAssets_obj::getImage'::`23'::_hx_Closure_0::_hx_run(Dynamic imageInfo) Line 183|C++|
| |FoxEditor.exe!`haxe::ui::ToolkitAssets_obj::getImage'::`23'::_hx_Closure_0::__run(const Dynamic & inArg0) Line 196|C++|
| |FoxEditor.exe!haxe::ui::backend::AssetsImpl_obj::getImageInternal(String resourceId, Dynamic callback) Line 147|C++|
| |FoxEditor.exe!haxe::ui::ToolkitAssets_obj::getImage(String resourceId, Dynamic callback, hx::Null<bool> __o_useCache) Line 198|C++|
| |FoxEditor.exe!haxe::ui::util::ImageLoader_obj::load(Dynamic callback) Line 118|C++|
| |FoxEditor.exe!haxe::ui::components::_Image::ResourceBehaviour_obj::validateData() Line 186|C++|
| |FoxEditor.exe!haxe::ui::behaviours::DataBehaviour_obj::validate() Line 110|C++|
| |FoxEditor.exe!haxe::ui::behaviours::Behaviours_obj::validateData() Line 214|C++|
| |FoxEditor.exe!haxe::ui::core::ComponentValidation_obj::validateComponentData() Line 459|C++|
| |FoxEditor.exe!haxe::ui::core::ComponentValidation_obj::validateComponentInternal(hx::Null<bool> __o_nextFrame) Line 408|C++|
| |FoxEditor.exe!haxe::ui::core::ComponentValidation_obj::validateComponent(hx::Null<bool> __o_nextFrame) Line 293|C++|
| |FoxEditor.exe!haxe::ui::core::ComponentValidation_obj::syncComponentValidation(hx::Null<bool> __o_nextFrame) Line 346|C++|
| |FoxEditor.exe!haxe::ui::core::ComponentValidation_obj::syncComponentValidation(hx::Null<bool> __o_nextFrame) Line 358|C++|
| |FoxEditor.exe!haxe::ui::core::ComponentValidation_obj::syncComponentValidation(hx::Null<bool> __o_nextFrame) Line 358|C++|
| |FoxEditor.exe!haxe::ui::containers::ScrollViewBuilder_obj::checkScrolls() Line 365|C++|
| |FoxEditor.exe!haxe::ui::containers::ScrollView_obj::validateComponentInternal(hx::Null<bool> __o_nextFrame) Line 235|C++|
| |FoxEditor.exe!haxe::ui::core::ComponentValidation_obj::validateComponent(hx::Null<bool> __o_nextFrame) Line 293|C++|
| |[Inline Frame] FoxEditor.exe!haxe::ui::validation::IValidating_obj::validateComponent(Dynamic) Line 27|C++|
| |FoxEditor.exe!haxe::ui::validation::ValidationManager_obj::process() Line 190|C++|
| |FoxEditor.exe!haxe::ui::validation::__ValidationManager_objprocess(hx::Object * inObj) Line 212|C++|
| |FoxEditor.exe!hx::CMemberFunction0::__Run(const Array<Dynamic> & inArgs) Line 48|C++|
| |[Inline Frame] FoxEditor.exe!Dynamic::operator()() Line 304|C++|
| |FoxEditor.exe!`kha::Scheduler_obj::addTimeTaskToGroup'::`2'::_hx_Closure_0::_hx_run() Line 480|C++|
| |FoxEditor.exe!`kha::Scheduler_obj::addTimeTaskToGroup'::`2'::_hx_Closure_0::__Run(const Array<Dynamic> & inArgs) Line 482|C++|
| |[Inline Frame] FoxEditor.exe!Dynamic::operator()() Line 304|C++|
| |FoxEditor.exe!kha::Scheduler_obj::executeTimeTasks(double until) Line 365|C++|
| |FoxEditor.exe!kha::Scheduler_obj::executeFrame() Line 282|C++|
| |FoxEditor.exe!kha::SystemImpl_obj::frame() Line 531|C++|
| |FoxEditor.exe!`anonymous namespace'::update() Line 154|C++|
| |[Inline Frame] FoxEditor.exe!kinc_internal_update_callback(...) Line 86|C++|
| |[Inline Frame] FoxEditor.exe!kinc_internal_frame(...) Line 189|C++|
| |[Inline Frame] FoxEditor.exe!kinc_start(...) Line 204|C++|

Is this running using a minimal test app? Any chance i could grab it? Just to make sure were doing the same thing… ive played (previously) with lists, tables and all was fine (for the previous issue)… so something is… … strange.

Cheers,
Ian

It seems a full rebuild of my project solved the missing assets issue. But the situation is still the same - say - if a png is missing from the resource folder it wont get embedded and when haxeui tries to show the image the app will crash. Solution would be to just dont try to add the image if it is null i guess?

Yeah, it sounds like that would make sense - a hard crash isnt ideal, i wonder why it didnt think it had the images though :confused: