Commit da89598
authored
MovableMan - fix usage of unordered_set::erase
`unordered_set::erase` invalidates the pointer that was erased.
https://en.cppreference.com/w/cpp/container/unordered_set/erase.html
> References and iterators to the erased elements are invalidated. Other iterators and references are not invalidated.
I also tested with a fresh C++ code file with `-fsanitize-address` and, indeed, the pattern of code of using an iterator variable to erase and then accessing through it reliably explodes.
---
What prompted this is that I have just had a completely random segfault crash originating from `SDL_Scancode ()` (????????) while playing the game. Here's the gdb backtrace (yes i play this game in debug build in gdb at this point lmao):
```
(gdb) bt
#0 0x0000555556b39558 in typeinfo name for SDL_Scancode ()
cortex-command-community#1 0x0000555555ae47aa in RTE::MovableMan::Update (this=0x555557453f50) at ../Source/Managers/MovableMan.cpp:1618
cortex-command-community#2 0x000055555567597c in RunGameLoop () at ../SourceMain.cpp:354
cortex-command-community#3 0x000055555567658a in main (argc=1 argv=0x7fffffffdc88) at ../Source/Main.cpp:468
```
The last sensible location in that backtrace is right after the erase.
Nothing seems to be broken with this applied.
---
There are comments and code around these spots that this commit touches that are apparently to work around the same issue I experienced. They're probably redundant/unneeded any more lol1 parent 07bb70b commit da89598
1 file changed
+9
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1484 | 1484 | | |
1485 | 1485 | | |
1486 | 1486 | | |
1487 | | - | |
1488 | | - | |
1489 | 1487 | | |
1490 | 1488 | | |
1491 | 1489 | | |
| |||
1494 | 1492 | | |
1495 | 1493 | | |
1496 | 1494 | | |
| 1495 | + | |
| 1496 | + | |
1497 | 1497 | | |
1498 | 1498 | | |
1499 | 1499 | | |
| |||
1504 | 1504 | | |
1505 | 1505 | | |
1506 | 1506 | | |
1507 | | - | |
1508 | 1507 | | |
1509 | 1508 | | |
| 1509 | + | |
1510 | 1510 | | |
1511 | 1511 | | |
1512 | 1512 | | |
| |||
1517 | 1517 | | |
1518 | 1518 | | |
1519 | 1519 | | |
1520 | | - | |
1521 | 1520 | | |
1522 | 1521 | | |
| 1522 | + | |
1523 | 1523 | | |
1524 | 1524 | | |
1525 | 1525 | | |
| |||
1571 | 1571 | | |
1572 | 1572 | | |
1573 | 1573 | | |
1574 | | - | |
1575 | 1574 | | |
| 1575 | + | |
1576 | 1576 | | |
1577 | 1577 | | |
1578 | 1578 | | |
| |||
1600 | 1600 | | |
1601 | 1601 | | |
1602 | 1602 | | |
1603 | | - | |
1604 | 1603 | | |
1605 | 1604 | | |
| 1605 | + | |
1606 | 1606 | | |
1607 | 1607 | | |
1608 | 1608 | | |
| |||
1614 | 1614 | | |
1615 | 1615 | | |
1616 | 1616 | | |
1617 | | - | |
1618 | 1617 | | |
1619 | 1618 | | |
| 1619 | + | |
1620 | 1620 | | |
1621 | 1621 | | |
1622 | 1622 | | |
| |||
1626 | 1626 | | |
1627 | 1627 | | |
1628 | 1628 | | |
1629 | | - | |
1630 | 1629 | | |
1631 | 1630 | | |
| 1631 | + | |
1632 | 1632 | | |
1633 | 1633 | | |
1634 | 1634 | | |
| |||
1658 | 1658 | | |
1659 | 1659 | | |
1660 | 1660 | | |
1661 | | - | |
1662 | 1661 | | |
1663 | 1662 | | |
| 1663 | + | |
1664 | 1664 | | |
1665 | 1665 | | |
1666 | 1666 | | |
| |||
0 commit comments