opentibiabr / canary

Canary Server 13.x for OpenTibia community.
https://docs.opentibiabr.com/
GNU General Public License v2.0
374 stars 619 forks source link

Server crash on "root" spell possibly? #2657

Closed rafalolszewski94 closed 5 months ago

rafalolszewski94 commented 5 months ago

Priority

High

Area

What happened?

While running through Rotten Wasteland at Soul War, somewhere in the middle of the main room, server crashes.

Relevant part of logs I found

2024-05-27 14:58:56 -  Thread 2 "canary" received signal SIGSEGV, Segmentation fault.
2024-05-27 14:58:56 -  [Switching to Thread 0x7ffff7a32640 (LWP 3455329)]
2024-05-27 14:58:56 -  0x000055555577baa2 in Map::moveCreature (this=0x5555564c3b28, creature=std::shared_ptr<Creature> (use count 7, weak count 8) = {...}, newTile=std::shared_ptr<Tile> (use count 2, weak count 3) = {...}, forceTeleport=false) at /root/canary/src/map/map.cpp:327
2024-05-27 14:58:56 -  327              Position oldPos = oldTile->getPosition();
2024-05-27 14:59:23 -  #0  0x000055555577baa2 in Map::moveCreature (this=0x5555564c3b28, creature=std::shared_ptr<Creature> (use count 7, weak count 8) = {...}, newTile=std::shared_ptr<Tile> (use count 2, weak count 3) = {...}, forceTeleport=false) at /root/canary/src/map/map.cpp:327
2024-05-27 14:59:23 -          oldTile = std::shared_ptr<Tile> (empty) = {get() = 0x0}
2024-05-27 14:59:23 -          oldPos = {x = 0, y = 0, z = 0 '\000'}
2024-05-27 14:59:23 -          newPos = {x = 0, y = 0, z = 0 '\000'}
2024-05-27 14:59:23 -          fromZones = <optimized out>
2024-05-27 14:59:23 -          toZones = <optimized out>
2024-05-27 14:59:23 -          teleport = <optimized out>
2024-05-27 14:59:23 -          spectators = {creatures = {container = std::vector of length -871307, capacity -5864063026098 = {std::shared_ptr<Creature> (expired, weak count 0) = {get() = 0x555556405358 <vtable for Map+16>}, std::shared_ptr<Creature> (use count 4390977, weak count 32766) = {get() = 0x5111}, <error reading variable: Cannot access memory at address 0x3f800008>, std::shared_ptr<Creature> (empty) = {get() = 0x5111}, std::shared_ptr<Creature> (empty) = {get() = 0x0}, std::shared_ptr<Creature> (expired, weak count 0) = {get() = 0x0}, std::shared_ptr<Creature> (empty) = {get() = 0x5555564c3b70}, std::shared_ptr<Creature> (use count 1651929701, weak count 1818701169) = {get() = 0x7fffd3e3fad0}, <error reading variable: Cannot access memory at address 0x37>,

My guess was the root spell colliding somehow with changes to Map::moveCreature

What OS are you seeing the problem on?

Linux

Code of Conduct

rafalolszewski94 commented 5 months ago

After commeting out root spell from monsters using it - still crash happens, so it's not root spell

rafalolszewski94 commented 5 months ago

Maybe this is related? https://github.com/opentibiabr/canary/commit/c57f5a28d6affef23dcf5a801b321d7e72465c52

mehah commented 5 months ago

@rafalolszewski94

Try this and see if everything works normally

void Map::moveCreature(const std::shared_ptr<Creature> &creature, const std::shared_ptr<Tile> &newTile, bool forceTeleport /* = false*/) {
    if (!creature || !newTile) {
        return;
    }

    auto oldTile = creature->getTile();

    if (!oldTile) {
        return;
    }