Skip to content

Improper initializing loop in TileMap.cpp #2

Description

@Sahil12S

While writing constructor of TileMap to initialize vector, there is one extra loop of layers that can be removed and resize statements should go outside the for loop. So, we resize all x coordinates by one statement, then for every x, we resize y, then for every y, we resize z. While in present code, we are resizing y for size of y, which will throw error if we go for rectangular map.
Resolution snippet:

// Initialize map
m_Map.resize( m_MapSize.x, std::vector< std::vector< Tile* > >() );

for ( int x = 0; x < m_MapSize.x; x++ )  {
m_Map[x].resize( m_MapSize.y, std::vector< Tile* >() );

    for ( int y = 0; y < m_MapSize.y; y++ )  {
        m_Map[x][y].resize( m_Layers, nullptr );
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions