Skip to content

Commit

Permalink
#5281: Fix a crash when passing an invalid layer ID to ILayerManager.…
Browse files Browse the repository at this point in the history
…setLayerVisibility
  • Loading branch information
codereader committed Oct 29, 2022
1 parent 679893c commit 05fdba5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions radiantcore/layers/LayerManager.cpp
Expand Up @@ -253,6 +253,8 @@ bool LayerManager::setLayerVisibilityRecursively(int rootLayerId, bool visible)

foreachLayerInHierarchy(rootLayerId, [&](int layerId)
{
if (layerId < 0 || layerId >= _layerVisibility.size()) return;

visibilityChange |= _layerVisibility.at(layerId) != visible;
_layerVisibility.at(layerId) = visible;
});
Expand Down
9 changes: 9 additions & 0 deletions test/LayerManipulation.cpp
Expand Up @@ -402,6 +402,15 @@ TEST_F(LayerTest, SetLayerVisibilityAffectsActiveLayer)
EXPECT_EQ(layerManager.getActiveLayer(), testLayerId) << "The test layer should now be active";
}

TEST_F(LayerTest, SetLayerVisibilityUsingInvalidId)
{
auto& layerManager = GlobalMapModule().getRoot()->getLayerManager();

// Hide non-existent layers
EXPECT_NO_THROW(layerManager.setLayerVisibility(333, false));
EXPECT_NO_THROW(layerManager.setLayerVisibility(-2, false));
}

TEST_F(LayerTest, SetLayerVisibilityAffectsNode)
{
loadMap("general_purpose.mapx");
Expand Down

0 comments on commit 05fdba5

Please sign in to comment.