divelist: when removing/adding a dive unregister/register fulltext

This fixes a crash: when the undo commands removed a dive from
the list, the fulltext cache was not cleared. If now the divelist
is reset and then the undo-command deleted, deletion of the owned
dive tries to remove it's fulltext cache, which doesn't exist
anymore.

For reasons of symmetry, when readding the dive, its fulltext
has to be registered.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-04-13 12:17:43 +02:00 committed by Dirk Hohndel
parent 3d4412ad1a
commit 103951bc78
2 changed files with 4 additions and 0 deletions

View file

@ -73,6 +73,7 @@ dive *DiveListBase::addDive(DiveToAdd &d)
res->hidden_by_filter = true;
int idx = dive_table_get_insertion_index(&dive_table, res);
fulltext_register(res); // Register the dive's fulltext cache
add_to_dive_table(&dive_table, idx, res); // Return ownership to backend
invalidate_dive_cache(res); // Ensure that dive is written in git_save()

View file

@ -753,6 +753,9 @@ struct dive *unregister_dive(int idx)
struct dive *dive = get_dive(idx);
if (!dive)
return NULL; /* this should never happen */
/* When removing a dive from the global dive table,
* we also have to unregister its fulltext cache. */
fulltext_unregister(dive);
remove_from_dive_table(&dive_table, idx);
if (dive->selected)
amount_selected--;