Skip to content

Cache clobbering when loading same file through FileLoader, ImageBitmapLoader, or ImageLoader #27301

@sxxov

Description

@sxxov

Description

Currently, all these 3 classes use the THREE.Cache data structure to store their caches. However, whilst all of them return different values, they all key by URL & it means loading the same URL the second time through a different loader will produce an incorrect result.

Reproduction steps

  1. Load a file using FileLoader
  2. Load a file using ImageBitmapLoader
  3. The returned value from ImageBitmapLoader will be the value from FileLoader, instead of an ImageBitmap

Code

import * as THREE from 'three';

THREE.Cache.enabled = true;

const fileLoader = new THREE.FileLoader();
file = await (new Promise((resolve) => {
	fileLoader.load(url, (v) => {
		resolve(v);
	});
}));

const imageBitmapLoader = new THREE.ImageBitmapLoader();
imageBitmap = await (new Promise((resolve) => {
	imageBitmapLoader.load(url, (v) => {
		resolve(v);
	});
}));

if (file === imageBitmap) throw new Error('Incorrect cached data!');

Live example

When on the page, press Enable cache to see the incorrect result.

Sorry, I'm not familiar with JSFiddle!

Screenshots

No response

Version

r159

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions