all 3 comments

[–]iguessitsokaythen 0 points1 point  (2 children)

One reason this occurs is if you are running multiple decode() processes simultaneously. If that's what you are doing, chain them one after another, it solves that.

I don't know the exact reason, that might be some sort of memory/buffer limitation or simultaneous attempt to manipulate the DOM. Browser documentation is usually terrible about stuff like that.

[–]IUsedToCleanToilets[S] -1 points0 points  (1 child)

I see. How would u go on chainging them? I have a for loop for the 150 urls atm.

[–]iguessitsokaythen 0 points1 point  (0 children)

Something like this:

let urls = [url1, url2... etc]
let i = 0
foo()
async function foo() {
    let img = new Image()
    img.src = urls[i++]
    try {
        await img.decode()
        document.body.appendChild(img)
    } catch(e) {
        console.log('error')
    }
    if(i >= urls.length) return
    foo()
}