megamarc / Tilengine

Free 2D graphics engine with raster effects for retro/classic style game development
https://www.tilengine.org
Mozilla Public License 2.0
847 stars 95 forks source link

Access violation error with more than 6 tilesets #120

Closed danielgholmes closed 1 month ago

danielgholmes commented 3 months ago

Hi Marc,

If there are tiles in a map from more than 6 different tilesets, it causes an access violation error most of the time. Sometimes a tile will be replaced with a tile from a different tileset which further confirms that there seems to be a memory access issue.

Here is an example which should help to reproduce the issue layers_test.zip

Using Tilengine v2.15.2

megamarc commented 3 months ago

Hi Daniel! How are you doing?I'm spending a week on holidays outside without my laptop. I'll take a look at the issue next week when I'll come back.Regards,El 19 jul. 2024 8:35, Daniel Holmes @.***> escribió: Hi Marc, If there are tiles in a map from more than 6 different tilesets, it causes an access violation error most of the time. Sometimes a tile will be replaced with a tile from a different tileset which further confirms that there seems to be a memory access issue. Here is an example which should help to reproduce the issue layers_test.zip Using Tilengine v2.15.2

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

megamarc commented 3 months ago

The "Tile" structure that holds each tile in a tilemap allocates 3 bits for the tileset, so up to 8 tilesets can be used in a single layer. Seems that the condition is unchecked, so the app crashes when bypassing the limit. The example you posted has 15 tilesets attached an 9 are used on a single layer.

There are still some status bits left that can be used to increase a bit the maximum number of tilesets and palettes (16 instead of 8 is a good value) and check the limits to avoid the crash. But these maximum numbers will always be fixed, you won't be able to create a map with an arbitrarily high number of tilesets or palettes, you'll have to stay within the limits.

danielgholmes commented 3 months ago

Thanks for clarifying. I doubt we would need more than 16 tilesets in a single layer in the future, but even so, we will make sure to adhere to that limit.