Facepunch / sbox-spritetools

MIT License
8 stars 2 forks source link

TilesetComponent: corrupted tile causing not generating collisions for tileset object #20

Open Jerichos opened 2 months ago

Jerichos commented 2 months ago

During generation of colliders there is for some reason a tile with position of -2147483520,-2147483648. This will cause exception: TypeSerializedProperty Error setting System.Boolean to True (System.Boolean)

repo to test, open scene Level Mountains: https://github.com/Jerichos/my_way_of_a_ninja.git

for now workaround is to detect a tile and remove it's tile position. Here is a snippet of code:

void RebuildMesh()
    {
        if (CollisionMesh is not null)
        {
            CollisionMesh = null;
            CollisionVertices.Clear();
            CollisionFaces.Clear();
        }
        CollisionBoxes.Clear();

        if (!HasCollider) return;
        if (Layers is null) return;

        var collisionLayer = Layers.FirstOrDefault(x => x.IsCollisionLayer);
        if (collisionLayer is null) collisionLayer = Layers.FirstOrDefault();
        if (collisionLayer is null) return;

        var tilePositions = new Dictionary<Vector2Int, bool>();

        // WORKAROUND: Remove 
        foreach (var tile in collisionLayer.Tiles)
        {
            tilePositions[Vector2Int.Parse(tile.Key)] = true;
            if (Vector2Int.Parse(tile.Key).x < -9999999 || Vector2Int.Parse(tile.Key).y < -9999999)
            {
                Log.Info($"WORKAROUND: removing Tile position: {tile.Key}");
                // log print: WORKAROUND: removing Tile position: -2147483520,-2147483648
                tilePositions.Remove(Vector2Int.Parse(tile.Key));
            }
        }

        if (tilePositions.Count == 0) return;

        var minPosition = tilePositions.Keys.Aggregate((min, next) => Vector2Int.Min(min, next));
        var maxPosition = tilePositions.Keys.Aggregate((max, next) => Vector2Int.Max(max, next));
        var totalSize = maxPosition - minPosition + Vector2Int.One;
        ...