diff --git a/src/laybasic/laybasic/layLayoutView.cc b/src/laybasic/laybasic/layLayoutView.cc index e43d930422..eda3aa1d4f 100644 --- a/src/laybasic/laybasic/layLayoutView.cc +++ b/src/laybasic/laybasic/layLayoutView.cc @@ -1935,6 +1935,10 @@ LayoutView::expand_properties (unsigned int index, const std::map &map void LayoutView::replace_layer_node (unsigned int index, const LayerPropertiesConstIterator &iter, const LayerPropertiesNode &node) { + if (index >= layer_lists ()) { + return; + } + // if the source specification changed, a redraw is required if (*iter != node) { @@ -1968,6 +1972,10 @@ LayoutView::replace_layer_node (unsigned int index, const LayerPropertiesConstIt void LayoutView::set_properties (unsigned int index, const LayerPropertiesConstIterator &iter, const LayerProperties &props) { + if (index >= layer_lists ()) { + return; + } + // if the source specification changed, a redraw is required const LayerProperties &l = *iter; if (l != props) { @@ -2007,6 +2015,8 @@ LayoutView::set_properties (unsigned int index, const LayerPropertiesConstIterat const LayerPropertiesNode & LayoutView::insert_layer (unsigned int index, const LayerPropertiesConstIterator &before, const LayerPropertiesNode &node) { + tl_assert (index < layer_lists ()); + if (transacting ()) { manager ()->queue (this, new OpInsertLayerProps (index, (unsigned int) before.uint (), node)); } else if (manager () && ! replaying ()) { @@ -2032,6 +2042,10 @@ LayoutView::insert_layer (unsigned int index, const LayerPropertiesConstIterator void LayoutView::delete_layer (unsigned int index, LayerPropertiesConstIterator &iter) { + if (index >= layer_lists ()) { + return; + } + lay::LayerPropertiesNode orig = *iter; if (mp_control_panel && index == current_layer_list ()) { diff --git a/testdata/ruby/layLayoutView.rb b/testdata/ruby/layLayoutView.rb index 71854fbdc0..1c2634fb0e 100644 --- a/testdata/ruby/layLayoutView.rb +++ b/testdata/ruby/layLayoutView.rb @@ -397,6 +397,13 @@ def test_3 lp.fill_color = 0xffff31cc assert_equal(lv.begin_layers.current.fill_color, 0xffff31cc) + # should not segfault + begin + lv.insert_layer(42, lv.begin_layers(42)) + assert_equal(true, false) + rescue => ex + end + end end