Skip to content

Commit aea34eb

Browse files
committed
Add virtual destructor to ApplicationContext and update tests
Added a virtual destructor to ApplicationContext for proper cleanup in derived classes. Updated map_spectators_test.cpp to use try_emplace instead of emplace for m_knownCreatures to avoid overwriting existing entries.
1 parent 3287ee3 commit aea34eb

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/framework/core/application.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ApplicationContext
2828
{
2929
public:
3030
ApplicationContext() = default;
31+
virtual ~ApplicationContext() = default;
3132
};
3233

3334
//@bindsingleton g_app

tests/map/map_spectators_test.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ TEST(MapSpectators, AggregatesCreaturesFromTiles)
285285
tile->addThing(first, -1);
286286
tile->addThing(second, -1);
287287

288-
map.m_knownCreatures.emplace(first->getId(), first);
289-
map.m_knownCreatures.emplace(second->getId(), second);
288+
map.m_knownCreatures.try_emplace(first->getId(), first);
289+
map.m_knownCreatures.try_emplace(second->getId(), second);
290290

291291
const auto expected = expectedSpectatorsFromTile(*tile);
292292

@@ -347,10 +347,10 @@ TEST(MapSpectators, AggregationMatchesLegacyTraversal)
347347
northTile->addThing(third, -1);
348348
aboveTile->addThing(fourth, -1);
349349

350-
map.m_knownCreatures.emplace(first->getId(), first);
351-
map.m_knownCreatures.emplace(second->getId(), second);
352-
map.m_knownCreatures.emplace(third->getId(), third);
353-
map.m_knownCreatures.emplace(fourth->getId(), fourth);
350+
map.m_knownCreatures.try_emplace(first->getId(), first);
351+
map.m_knownCreatures.try_emplace(second->getId(), second);
352+
map.m_knownCreatures.try_emplace(third->getId(), third);
353+
map.m_knownCreatures.try_emplace(fourth->getId(), fourth);
354354

355355
const bool multiFloor = true;
356356
const int range = 3;
@@ -381,9 +381,9 @@ TEST(MapSpectators, RangeFiltering)
381381
adjTile->addThing(c2, -1);
382382
farTile->addThing(c3, -1);
383383

384-
map.m_knownCreatures.emplace(c1->getId(), c1);
385-
map.m_knownCreatures.emplace(c2->getId(), c2);
386-
map.m_knownCreatures.emplace(c3->getId(), c3);
384+
map.m_knownCreatures.try_emplace(c1->getId(), c1);
385+
map.m_knownCreatures.try_emplace(c2->getId(), c2);
386+
map.m_knownCreatures.try_emplace(c3->getId(), c3);
387387

388388
{
389389
const auto nearSpectators = map.getSpectatorsInRangeEx(center, false, 1, 1, 1, 1);
@@ -418,9 +418,9 @@ TEST(MapSpectators, CreatureOrderingIsDeterministic)
418418
centerTile->addThing(middle, -1);
419419
eastTile->addThing(east, -1);
420420

421-
map.m_knownCreatures.emplace(west->getId(), west);
422-
map.m_knownCreatures.emplace(middle->getId(), middle);
423-
map.m_knownCreatures.emplace(east->getId(), east);
421+
map.m_knownCreatures.try_emplace(west->getId(), west);
422+
map.m_knownCreatures.try_emplace(middle->getId(), middle);
423+
map.m_knownCreatures.try_emplace(east->getId(), east);
424424

425425
const auto expected = std::vector<CreaturePtr>{ west, middle, east };
426426

@@ -452,9 +452,9 @@ TEST(MapSpectators, MultiFloorRangeIncludesVerticalNeighbors)
452452
centerTile->addThing(middle, -1);
453453
aboveTile->addThing(above, -1);
454454

455-
map.m_knownCreatures.emplace(below->getId(), below);
456-
map.m_knownCreatures.emplace(middle->getId(), middle);
457-
map.m_knownCreatures.emplace(above->getId(), above);
455+
map.m_knownCreatures.try_emplace(below->getId(), below);
456+
map.m_knownCreatures.try_emplace(middle->getId(), middle);
457+
map.m_knownCreatures.try_emplace(above->getId(), above);
458458

459459
const auto spectators = map.getSpectatorsInRangeEx(center, true, 0, 0, 0, 0);
460460
const auto expected = std::vector<CreaturePtr>{ below, middle, above };
@@ -479,7 +479,7 @@ TEST(MapSpectators, UniqueCreatures)
479479
firstTile->addThing(shared, -1);
480480
secondTile->addThing(shared, -1);
481481

482-
map.m_knownCreatures.emplace(shared->getId(), shared);
482+
map.m_knownCreatures.try_emplace(shared->getId(), shared);
483483

484484
const auto spectators = map.getSpectatorsInRangeEx(center, false, 1, 1, 0, 0);
485485
ASSERT_EQ(1u, spectators.size());

0 commit comments

Comments
 (0)