Texture cache overflow: 16 texture units available.

Recommended Posts

Using MelonJS 5.1 (I cannot upgrade at this point), I'm creating a fairly large adventure game. My TMX map loaded fine until I added water tile layer:

At which point I started getting error: Texture cache overflow: 16 texture units available.

Error name is

Digging into the code, I see there is a max size for the Texture Cache:

        validate : function () {
            if (this.length >= this.max_size) {
                // TODO: Merge textures instead of throwing an exception
                throw new
                    "Texture cache overflow: " + this.max_size +
                    " texture units available."

How can I fix this?

Btw this seems to have been fixed in 2015:

@obiot @Parasyte

Share this post

Link to post
Share on other sites

the issue is that WebGL has a limited amount of texture, and as of today the limit is 16 for ~70% of devices :

in my opinion the only way to fix that is either to pack/merge your tilesets directly, or to use TexturePacker (that was the fix back in 2015) when possible (



Share this post

Link to post
Share on other sites

@obiot This bug is happening again, but only on Mandarin version, even though I'm loading I think fewer overall assets than the working Spanish version.

Question: what are texture units (i.e., what does "16 texture units" mean?) and how do I compare it to overall loaded texture size?

If I print out game.map_texture, how do I compare it to see if it's below 16 units?

        game.map_texture = new

Mandarin Version: Printing out length for my three texture atlases: 

console.log('Game Texture: ', Object.keys(game.texture.atlas).length, game.texture);

> length of game.texture.atlas is 1236

console.log('Game Map Texture: ', Object.keys(game.map_texture.atlas).length, game.map_texture);

> length of game.map_texture.atlas is 354

console.log('Game Player Texture: ', Object.keys(game.player_texture.atlas).length, game.player_texture);

> length of game.player_texture.atlas is 107

Working Spanish Version: Printing out length for my three texture atlases: 

> length of game.texture.atlas is 1215

> length of game.map_texture.atlas is 358

> length of game.player_texture.atlas is 107


Mind checking the game out?



Use promo code "LEEROY" for free full game access. You're able to see the asset list loaded.

Images of my packed assets on disk:

Spanish: - map items - texture

Mandarin: - map items - texture




Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.