Jump to content

Error message would not pop out right after an asset is loaded


Herbert
 Share

Recommended Posts

Sorry I don't quite get it, my understanding for errorCallback is that it will be called when the asset is failed to be loaded, but in this case the asset is loaded successfully, just something goes wrong in my onsuccess callback.
Actually the one I use is assetsManager.onFinish, it has the same issue. 

I will temporary remove the solved tag since I am still a bit confused.

Link to comment
Share on other sites

Actually, the error in the load callback is triggering the error callback explaining the behavior you have.

I agree now it is a bit strange but we could consider the callback as part of the loading process where you might rearrange your meshes and so on.

I am a bit wondering if we should change this behavior knowing some user are probably already relying on it in their app and this would be a breaking change.

Summoning @Deltakosh for pragmatism and breaking changes :-)

 

 

Link to comment
Share on other sites

Just think about the error callback as a one big try-catch. Any error inside will trigger it. So, error is "something went wrong while trying to do what you wanted", instead of "something went wrong with those specific assets".

The error callback's second variable is a message coming from babylonjs (https://www.babylonjs-playground.com/#11BH6Z#316).  The 3rd variable SHOULD be the exception, but I just found out that we are not calling the onError with the exception. I am fixing this now. Will that be enough?

 

Link to comment
Share on other sites

Thanks @RaananW, as long as I can see the original message for development.
What about assetManager? Any way I can catch the error message in onFinish?
I print out the second and third variables of onTaskError, they are both undefined .

var assetsManager = new BABYLON.AssetsManager(scene);
assetsManager.addMeshTask("dude", "", "Scenes/Dude/", "Dude.babylon");

assetsManager.onFinish = function(task) {
    console.log(a.a);
};
Link to comment
Share on other sites

Just made a few changes in the way we handle errors (or better yet - error callbacks) in both the loader and the assets manager. I want the rest of the team to review the changes before merging, but you can see the changes here - 

https://github.com/BabylonJS/Babylon.js/pull/2890

In general, message (string) and exception (any / error / js exception) were added to most onError callbacks.

Link to comment
Share on other sites

Another update regarding this issue - 

AssetsManager now has better error handling (and 3 new observables to handle task success, error, and all tasks done).

What's important in this case, is that if there is an error in the onSuccess callback (like in your case), an error will be displayed in the console. If you have an onError callback defined, you will actually get the exception thrown so you can dig further and understand what went wrong.

The changes were just merged, I will build a nightly soon, so expect to see it in the playground pretty soon.

Link to comment
Share on other sites

Thanks for super fast fix:)
SceneLoader.ImportMesh works great.
However, I still can't get the error message in onFinish callback(I tried the combination as shown below)

Also, onTasksDoneObservable does not fire like onFinish while all tasks done.

// task done
assetsManager.onTaskSuccess = () => {
    console.log(a.a);
};

assetsManager.onTaskSuccessObservable.add(() => {
    console.log(a.a);
});

// catch error
assetsManager.onTaskError = (i, j, k) => {
    console.log(i, j, k);
};

assetsManager.onTaskErrorObservable.add((i ,j ,k) => {
    console.log(i, j, k);
});

// all tasks done
assetsManager.onTasksDoneObservable.add(() => {
    console.log(a.a);
});

assetsManager.onFinish = () => {
    console.log(a.a);
}

 

Link to comment
Share on other sites

@Herbert -

I've found the assetsManager.onFinish to cause errors for several BJS versions all the way back to before 2.0. It often reports that all assets are loaded before it has finished and everything is actually cached. It happens most often in my scenes when I'm loading allot of small assets such as low res textures - especially when building GUIs and loading the assets to use in extensions. So I often find that once my scene is loaded, there are images missing from my scene and/or from the GUI. And since the AssetsManager loads in sequence, as logic dictates, it will always be the assets at the very end if the list which aren't loaded when my scene initializes when onLoad reports true.

I gave up trying to solve this problem at least 2 years ago, and do have a work around. I create 2 or 3 very small power of two textures at 32px X 32px and simply call them "dummy_texture1.png", "dummy_texture2.png", and so on. These are never meant to be used, and in all of my testing, I've rarely seen the Assets Manager miss more than 1 or 2 textures at most. 2 appears to be the limit for me generally. I know this is a ridiculous solution, but I don't have another and can't have my scenes initializing with missing assets. So I place 2 or 3 of these tiny "dummy" textures at the end of my list of assets to load, and my scene is still often loaded before all assets are cached - however I receive no errors as the "dummy" textures are never called, and don't really use any resources to ever consider when they do load.

Again, not a very eloquent solution, however I never have the problem of my scene initializing with missing assets - forcing the user to reload. And I'll mention again that I've worked on trying to solve this in every way I can think of down to memory allocation calls; but had to give up as I simply couldn't find a consistent solution. And I never want users to be forced to refresh their scenes due to missing textures and/or assets. Of course this generally happens when I'm loading allot of assets prior to scene initialization - but create and load small dummy textures to the end of the list and it will never happen. I hate to even mention that I do this routinely, but I've found no better choice personally.

Cheers,

DB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...