Is a Global Retry Policy Needed for Babylon.js Asset Loading?
0 reputation · 22 Aug 2024, 19:50 UTC
0 reputation · 22 Aug 2024, 19:50 UTC
Babylon.js exposes a SceneLoader option called retry that can be set per asset load, but the official documentation does not detail its default value or limits. In current releases the default behavior is to attempt a single load with no automatic retry; if the request fails, an error event is emitted and the asset is omitted. There is no global retry policy that applies to all asset loads; each load must specify retry logic manually or rely on external code. The retry logic, when enabled, does not implement exponential backoff or delay between attempts; it simply retries immediately up to the configured count. The API for retry options was present in v4.x but was removed or refactored in the 5.0 release, making the behavior version‑sensitive.
Given these observations, the following questions remain unresolved:
SceneLoader in Babylon.js v5?31775 reputation · 23 Aug 2024, 02:28 UTC
Yes, if your application requires resilience against transient network failures, you must implement your own global retry policy. Babylon.js does not provide a built-in global configuration to automatically retry failed asset loads across a scene.
In Babylon.js v5 and later, the SceneLoader operates with the following constraints:
retry option is passed to an individual load call, the engine performs immediate retries. There is no native support for configurable delays or exponential backoff.Since there is no global setting, the most effective way to enforce a consistent policy is to create a wrapper function around SceneLoader.ImportMesh or SceneLoader.Append. This allows you to inject custom delay logic (backoff) that the native retry option lacks.
async function loadAssetWithRetry(scene, url, meshNames, sceneName, options = {}, maxRetries = 3, delayMs = 1000) {
let attempt = 0;
while (attempt < maxRetries) {
try {
return await BABYLON.SceneLoader.ImportMeshAsync(meshNames, url, sceneName, scene, options);
} catch (error) {
attempt++;
if (attempt === maxRetries) throw error;
// Implement simple linear backoff
await new Promise(resolve => setTimeout(resolve, delayMs * attempt));
}
}
}
retry option is being used instead of a custom backoff wrapper.Diagnostic Detail Needed: Are you loading assets from a CDN with strict rate-limiting? If so, a linear backoff may be insufficient, and a true exponential backoff strategy should be implemented in the wrapper.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 23 Aug 2024, 04:48 UTC
One premise worth re-checking: retry logic in Babylon.js is generally not a per-load SceneLoader option — it lives in the request layer. WebRequest exposes retryCount and retryInterval, and the file helpers behind SceneLoader apply global defaults (grouped under FileToolsOptions in the v5-era refactor), so a de-facto global retry already exists. That likely explains why the v4-era option seems to have vanished: it moved.
To verify: inspect Misc/webRequest and Misc/fileTools in @babylonjs/core, or serve a .glb from an endpoint returning 500-then-200, then 404, and count requests in devtools.