Closed edwood-grant closed 1 year ago
Here's the fixed file:
import kha.Image;
import kha.System;
import kha.Assets;
import kha.Blob;
import kha.AssetError;
class Main {
public static function main() {
System.start({title: "Shader", width: 640, height: 480}, function(_) {
trace("Trying to load data");
// Assets.loadBlobFromPath("config.txt", onLoadBlobSuccess, onLoadFailure);
Assets.loadImage("player", onLoadImageSuccess, onLoadFailure);
});
}
static function onLoadImageSuccess(img:Image):Void {
trace("Image loaded!");
trace('Image size is: (${img.width}, ${img.height})');
// Stopping all
System.stop();
}
static function onLoadBlobSuccess(blob:Blob):Void {
trace("Blob loaded! Contents are:");
trace('\n${blob.toString()}');
// Stopping all
System.stop();
}
static function onLoadFailure(error:AssetError):Void {
trace('Failed to load data. URL is ${error.url} ');
// Stopping all
System.stop();
}
}
System.start has to be called before anything else, that's why nothing was loaded. It initializes Kha and for C++-targets that's also what spins up the loader-thread. I also changed the loadImageFromPath call to loadImage. The reason is that player.png gets converted to player.k when you add it via addAssets to speed up loading (png files are very slow to load because they are essentially zip files). With loadImage you automatically get the path-translation for that. Alternatively you could also just copy the png files into build/windows or whatever your current target is and then use loadImageFromPath for any file-type which Kha supports (which does include pngs and jpegs).
Describe the bug It seems that Kaha never manages to resolve any attempts to load files. It never trigger either the succes or failure callback. The appñlication then hangs eterneally and never shutsdown, leaving an empty background process behind f run without debugging. Breakpopints can never catch this problem.
This was tested on windows only. In the HTML5 debug everything works ok and it souhld tirgger failure or success as expected.
To Reproduce Steps to reproduce the behavior:
Expected behavior On windowws: Expected to attempt to load and either triggger a success or a failure to load data
Execution Environment:
Additional context I did not test all data types, but I assume that this will also fail on sounds and video files. also tested ion windows only, no idea if this has effects on other platforms as well.