AssetManager load in promise broken

Just updated from 3.1 to 4.0 and all loading with AssetManager are broken.

https://playground.babylonjs.com/#Y7XMAR#28 here the link to reproduce the bug. Change isUsingPromise to see different behavior. Expected same behavior.

I use promises to load AssetManager. Promises in js is always async.
Promise.resolve().then(() => console.log(1)); console.log(2); will produce 2,1

In the line assetsManager.ts#L1009 you can see splicing tasks array.

Here is what happening.

  1. AssetManager.onFinish calls with all tasks
  2. Next promise in chain is scheduled by browser with all tasks
  3. AssetManager._decreaseWaitingTasksCount - removing successful tasks (Why? Second call AssetManager.load?)
  4. Function in Promise.then fires with empty array of tasks
1 Like

Thanks for the fix!!!

1 Like

As workaround its need to accumulate tasks in your own array or use var tasks = assetManager._tasks.slice() before calling assetManager.load().

1 Like