Skip to content

Some strange things happen with delete data. #13

@wearplugins

Description

@wearplugins

Some strange things happen. I set the data to the map editor (tile id 0) and delete the data from the BatchHandle.

if (Event.current.button == 1)
                    {
                        if (region.TileView != null)
                        {
                            _regionsMap.DeleteTile(region);
                        }
                    }
public void DeleteTile(Region region)
{
    if (region == null || region.TileId == 0)
        return;
    
    InstanceRenderer.Remove(region.TileView);
    region.TileView = null;
    region.TileId = 0;
}
// <summary> </summary>
        /// <param name="node"></param>
        public void Remove(BatchNode node)
        {
            _containers[node.BatchIndex].Remove(node.Index);
        }
/// <summary> </summary>
/// <param name="nodeIndex"></param>
public void Remove(int nodeIndex)
{
    var dataBuffer = _batchHandle.AsInstanceDataBuffer();
    dataBuffer.Remove(nodeIndex, 1);
}

But the data is not deleted and the tile does not disappear. After that the map is saved and reloading. The tiles are back in place and there are no deleted ones.

/// <summary> </summary>
public void CreateViews()
{
    foreach (var region in Grid)
        if (region != null && region.TileId > 0)
                CreateTileView(region);
    InstanceRenderer.Populate();
}

/// <summary> </summary>
public void CreateTileView(Region region)
{
    var tileData = _coreCollection.Get<GeoscapeTileData>(region.TileId);
    if (tileData != null)
    {
        var renderer = tileData.View.GetComponent<MeshRenderer>();
        var meshFilter = tileData.View.GetComponent<MeshFilter>();
        region.TileView = InstanceRenderer.AddCached(meshFilter.sharedMesh, renderer.sharedMaterial, Color.white,
            region.Position, Quaternion.identity, Vector3.one);
    }
}
/// <summary>
/// 
/// </summary>
public void PopulateCache()
{
    if (_cacheNodes==null || _cacheNodes.Count == 0)
        return;
    
    var dataBuffer = _batchHandle.AsInstanceDataBuffer();

    // this number can be not a constant, but less than BatchDescription.MaxInstanceCount
    dataBuffer.SetInstanceCount(_cacheNodes.Count); 

    for (var i = 0; i < _cacheNodes.Count; i++) 
    {
        var node = _cacheNodes[i];
        dataBuffer.SetTRS(i, node.Position, node.Rotation, node.Scale);
        dataBuffer.SetColor(i, _baseColorPropertyId, new Color(0.2f, 0.2f, 0.8f, 1f));
    }

    _batchHandle.Upload();

    _cacheNodes.Clear();
    _cacheNodes = null;
}

After assembling the build, the same thing happens, all deleted tiles are displayed.

What do you think could be the problem?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions