[SOLVED] Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH

Hello!
I randomly get an error for my textures that is dynamically loaded:
Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH

image
image

I can’t catch this bug, because it happens at random time

How are you trying to load it? Can you provide an example project and/or code?

AssetLoader.loadAssets = function(assets, onAssetLoaded, onAllAssetsLoaded, priority = 1) {

    var assetsToLoad = [];
    for (let i = 0; i < assets.length; i++) {
        if (assets[i].loaded) { 
            if (onAssetLoaded) {
                onAssetLoaded(assets[i]);
            }
            continue; 
        }
        // if (AssetLoader.assetPriorityQueue.data.indexOf(assets[i]) == -1) { continue; }
        assets[i].priority = priority;
        assetsToLoad.push(assets[i]);
    }

    if (assetsToLoad.length === 0) { return; }

    for (let i = 0; i < assetsToLoad.length - 1; i++) {
        assetsToLoad[i].next = assetsToLoad[i + 1];
        assetsToLoad[i].onAssetLoaded = onAssetLoaded;
        assetsToLoad[i].ready(this.onQueueAssetLoaded.bind(this));
    }

    lastAsset = assetsToLoad.length - 1;
    assetsToLoad[lastAsset].priority = priority - 1;
    assetsToLoad[lastAsset].onAssetLoaded = onAssetLoaded;
    assetsToLoad[lastAsset].onAllAssetsLoaded = onAllAssetsLoaded;
    assetsToLoad[lastAsset].ready(this.onQueueAssetLoaded.bind(this));
    
    for (let i = 0; i < assetsToLoad.length; i++) {
        this.assetPriorityQueue.push(assetsToLoad[i]);
    }
    
    if (this.assetPriorityQueue.data.length === assetsToLoad.length) {
        var firstAsset = this.assetPriorityQueue.pop();
        this.app.assets.load(firstAsset);
    }

};

AssetLoader.onQueueAssetLoaded = function(asset) {

    if (asset.onAssetLoaded) {
        asset.onAssetLoaded(asset);
    }

    if (asset.onAllAssetsLoaded) {
        asset.onAllAssetsLoaded();
    }

    var nextAsset = this.assetPriorityQueue.pop();
    if (!nextAsset) { return; }


    this.app.assets.load(nextAsset);
};

AssetLoader.unloadAssets = function(assets) {
    assets.forEach(function(asset) {
        if (this.assetPriorityQueue.data.indexOf(asset) !== -1) { return; }
        asset.unload();
    }.bind(this));
};
Panorama.prototype.onTextureLoaded = function(texture) {
    DebugHelper.printDebugMessage(this, "Loaded:", texture.name);
    
    if (this.onTextureLoadedCallback) {
        this.onTextureLoadedCallback(texture);
    }
    
    var id = this.textures.indexOf(texture);
    if (id < 0) { return; }
    
    this.materials[id].opacity = 0;
    this.materials[id].emissiveMap = this.textures[id].resource;
    this.materials[id].update();
};


Panorama.prototype.onAllTexturesLoaded = function() {
    DebugHelper.printDebugMessage(this, "onAllTexturesLoaded");
    
    if (this.onAllTexturesLoadedCallback) {
        this.onAllTexturesLoadedCallback();
    }
};

Under project settings, what value is Asset Retries? If 0, try it at 5. This will retry loading the resource if an error occurs.

1 Like

Thx, I’ll try it!

Yes, it works!
Thx!

1 Like

That’s great! At a guess, the project is loading many assets/files and sometimes one or two fail to load due to random network error.