Fix fatal bug in wxGridSelection::DeselectBlock()

The selBlock reference could be used after the vector invalidation,
which resulted in using the wrong vector element at best and could
probably lead to a crash at worst.

Don't use it after invalidating the vector any longer.

This notably fixes a bug in row-or-column selection mode where the grid
wasn't updated visually after modifying its selection by deselecting a
single cell as soon as there were more than one selected row or column.
This commit is contained in:
Vadim Zeitlin 2020-04-12 18:57:59 +02:00
parent 4f7ed07f5e
commit 9b031be8d1

View File

@ -290,14 +290,15 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
break;
}
// remove the block
const wxGridBlockDiffResult result =
selBlock.Difference(canonicalizedBlock, splitOrientation);
// remove the block (note that selBlock, being a reference, is
// invalidated here and can't be used any more below)
m_selection.erase(m_selection.begin() + n);
n--;
count--;
wxGridBlockDiffResult result =
selBlock.Difference(canonicalizedBlock, splitOrientation);
for ( int i = 0; i < 2; ++i )
{
const wxGridBlockCoords& part = result.m_parts[i];