otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.58k stars 1.05k forks source link

Reloading monsters crashes server with revscriptsys. #2690

Closed Oen44 closed 4 years ago

Oen44 commented 4 years ago

Before creating an issue, please ensure:

Steps to reproduce (include any configuration/script required to reproduce)

  1. Use /reload spells or /reload monsters command

Expected behaviour

Spells and monsters should be reloaded properly, without crash.

Actual behaviour

Server crashes when trying to reload monsters.

To prove this, comment out reloading monsters when reloading spells. There will be no crash.

EPuncker commented 4 years ago

are you sure that you are using TFS from THIS github? I'm using it as well and no crash for me, and I have lots of things converted into revscriptsys yet, no crashes:

(despite the new sprites, it still 10.98, and ignore the errors on console because I'm too lazy to fix them) 64b37d19-4b1b-4fd8-bda2-82359b4af632

unmodified TFS do not crash at all also

Oen44 commented 4 years ago

are you sure that you are using TFS from THIS github? I'm using it as well and no crash for me, and I have lots of things converted into revscriptsys yet, no crashes:

(despite the new sprites, it still 10.98, and ignore the errors on console because I'm too lazy to fix them) 64b37d19-4b1b-4fd8-bda2-82359b4af632

Yes I'm sure :) This happens not only with my TFS but others too. I'm few commits behind but they are mostly typo corrections. I have only 4 monsters created using revscriptsys.

EPuncker commented 4 years ago

please provide script and step-by-step so others can reproduce it

Oen44 commented 4 years ago

please provide script and step-by-step so others can reproduce it

There is more than just a monster script. These are monsters with custom attacks, I would have to provide you every lib file and everything. Removing all lines of code that are not related to MonsterType is a way to prevent crashes, but this should not happen because there is more code than expected.

EPuncker commented 4 years ago

okay, good luck with this issue!

Oen44 commented 4 years ago

Good luck with revscriptsys when you will try to make something more than just another Rat and everything will stop working.

Znote commented 4 years ago

I tried the provided steps to reproduce.

Failed to reproduce.

Please provide the correct steps to reproduce this bug. Else its gonna be difficult to fix.

Oen44 commented 4 years ago

I just did more testing by removing less codes of lines than before to see if there is something particular causing server crash. Well, MonsterType.onThink and MonsterType.onAppear events are exactly what is causing this. Even if they are empty functions, as long as they are declared, server is crashing. What's more confusing, crash isn't happening immediately after command is used, sometimes everything is working for like 3-5 seconds and then server crashes.

Steps to reproduce

  1. Create new MonsterType using revscriptsys
  2. Add onThink or onAppear event
  3. Reload monsters
local mType = Game.createMonsterType("Prayer Guardian")

local mob = {}
mob.description = "Prayer Guardian"
mob.experience = 0
mob.outfit = {
    lookType = 128,
    lookHead = 78,
    lookBody = 78,
    lookLegs = 78,
    lookFeet = 78,
    lookAddons = 0
}

mob.health = 1500
mob.maxHealth = mob.health
mob.race = "fire"
mob.speed = 250
mob.maxSummons = 0

function mType.onThink(monster, interval)
end

function mType.onAppear(monster, creature)
end

mType:register(mob)
EvilHero90 commented 4 years ago

Do you have a stack trace? tried to reproduce this a few times now, I couldn't get the server to crash so far.

Oen44 commented 4 years ago

More testing! Looks like there is one more thing needed to make it crash. Which maybe is related to another issue - loading order, however I thought that this will need separated issue thread. GlobalEvent onThink with interval set to different than 1000 is colliding with MonsterType onThink. If MonsterType script is loaded after GlobalEvent script, then MonsterType onThink interval is the same as in GlobalEvent script and MonsterType.onAppear(monster, creature) is now MonsterType.onAppear(interval). Try to use monster script from previous comment and this GlobalEvent. Now reloading should crash the server.

local event = GlobalEvent("myevent")

function event.onThink(interval)
    return true
end

event:interval(3350)
event:register()
EPuncker commented 4 years ago

yeah, now it crashes

Oen44 commented 4 years ago

I then completely removed onThink/onAppear/onDisappear/onMove/onSay and tested again and there was no crash when reloading.

Now add GlobalEvent and try again, without MonsterType events.

Znote commented 4 years ago

I have added a tutorial on how to compile with debug symbols and get stack trace: https://github.com/otland/forgottenserver/wiki/Compiling-debug-binaries-in-cmake

Znote commented 4 years ago

@EvilHero90

Do you have a stack trace? tried to reproduce this a few times now, I couldn't get the server to crash so far.

0: Compile binary with debug flag and run server in gdb

1: Create file example.lua: data/scripts/monsters/example.lua

2: Login as GM, summon the monster outside of depot.

3: Login as normal character, walk out of depot, freak out when it (a demon skeleton) begins to summons demons, XD head back into depot and logout.

4: login as GM, execute command /reload scripts without doing any changes to the Lua code 5: Crash

#0  0x00007ffffe7a6742 in ?? () from /usr/lib/x86_64-linux-gnu/liblua5.2.so.0
No symbol table info available.
#1  0x00007ffffe7a765c in lua_rawgeti () from /usr/lib/x86_64-linux-gnu/liblua5.2.so.0
No symbol table info available.
#2  0x0000000008223f39 in LuaScriptInterface::pushFunction(int) (this=0x7ffff413a370, functionId=1003) at /ubuntu18/TFS-Master/src/luascript.cpp:493
No locals.

#3  0x0000000008164821 in Monster::onCreatureMove (this=0x7ffff4c3b210, creature=0x7ffff4c6a890, newTile=0x7ffff6fd0ee0, newPos=..., oldTile=0x7ffff6fd0f70, oldPos=..., teleport=false) at /ubuntu18/TFS-Master/src/monster.cpp:207
        scriptInterface = 0x7ffff413a370
        env = 0x86eefc0 
        L = 0xffffffff00013880

#4  0x0000000008159ef0 in Map::moveCreature (this=0x86efc50 , creature=warning: RTTI symbol not found for class 'Player [clone .lto_priv.11326]'
..., newTile=..., forceTeleport=false) at /ubuntu18/TFS-Master/src/map.cpp:296
        spectator = 0x7ffff4c3b210
        __for_range = @0x7ffffbd7f8c0: {Python Exception  Type is not a template.:
vec = {}}
        __for_begin = 0x7ffff4c3b210
        __for_end = 0x0
        oldTile = @0x7ffff6fd0f70: {ground = 0x7ffff6fd0f40, tilePos = {x = 109, y = 362, z = 6 '\006'}, flags = 128}
        oldPos = {x = 109, y = 362, z = 6 '\006'}
        newPos = {x = 109, y = 361, z = 6 '\006'}
        teleport = false
        spectators = {Python Exception  Type is not a template.:
vec = {}}
        newPosSpectators = {Python Exception  Type is not a template.:
vec = {}}
        oldStackPosVector = Python Exception  Type is not a template.:
{}
        leaf = 0x7ffff6fcbe00
        new_leaf = 0x7ffff6fcbe00
        i = 1

#5  0x00000000082e4fd5 in Game::internalMoveCreature(Creature&, Tile&, unsigned int) (this=0x86efc00 , creature=warning: RTTI symbol not found for class 'Player [clone .lto_priv.11326]'
..., toTile=..., flags=32) at /ubuntu18/TFS-Master/src/game.cpp:815
        ret = RETURNVALUE_NOERROR
        index = 32518
        toItem = 0x86efc50 
        subCylinder = 0x7ffffbd7f970
        toCylinder = 0x7ffff6fcbe00
        fromCylinder = 0x7ffff6fcdf30
        n = 4225171817

#6  0x00000000082e4f1f in Game::internalMoveCreature(Creature*, Direction, unsigned int) (this=0x86efc00 , creature=0x7ffff4c6a890, direction=DIRECTION_NORTH, flags=32) at /ubuntu18/TFS-Master/src/game.cpp:804
        currentPos = @0x7ffff4c6a898: {x = 109, y = 361, z = 6 '\006'}
        destPos = {x = 109, y = 361, z = 6 '\006'}
        player = 0x7ffff4c6a890
        diagonalMovement = false
        toTile = 0x7ffff6fd0ee0

#7  0x0000000008319fdd in Creature::onWalk (this=0x7ffff4c6a890) at /ubuntu18/TFS-Master/src/creature.cpp:195
        ret = RETURNVALUE_NOERROR
        dir = DIRECTION_NORTH
        flags = 32

#8  0x00000000082f1e04 in Game::checkCreatureWalk(unsigned int) (this=0x86efc00 , creatureId=268435458) at /ubuntu18/TFS-Master/src/game.cpp:3563
        creature = 0x7ffff4c6a890

#9  0x000000000831a43e in Creature::addEventWalk (this=0x7ffff4c6a890, firstStep=true) at /ubuntu18/TFS-Master/src/creature.cpp:280
        ticks = 1

#10 0x000000000831a363 in Creature::startAutoWalk (this=0x7ffff4c6a890, Python Exception  There is no member or method named _M_impl.:
listDir=) at /ubuntu18/TFS-Master/src/creature.cpp:258
        size = 1

#11 0x00000000082e99b7 in Game::playerMove(unsigned int, Direction) (this=0x86efc00 , playerId=268435458, direction=DIRECTION_NORTH) at /ubuntu18/TFS-Master/src/game.cpp:1802
        player = 0x7ffff4c6a890

#12 0x000000000808fc71 in std::__invoke_impl(std::__invoke_memfun_deref, void (Game::*&)(unsigned int, Direction), Game*&, unsigned int&, Direction&) (__f=
    @0x7ffff41df130: (void (Game::*)(struct Game *, unsigned int, enum Direction)) 0x82e98fa , __t=@0x7ffff41df148: 0x86efc00 , __args#0=@0x7ffff41df144: 268435458, __args#1=@0x7ffff41df140: DIRECTION_NORTH) at /usr/include/c++/7/bits/invoke.h:73
No locals.

#13 0x00000000080caaba in __invoke (__fn=@0x7ffff41df130: (void (Game::*)(struct Game *, unsigned int, enum Direction)) 0x82e98fa , __args#0=@0x7ffff41df148: 0x86efc00 , __args#1=@0x7ffff41df144: 268435458, __args#2=@0x7ffff41df140: DIRECTION_NORTH)
    at /usr/include/c++/7/bits/invoke.h:95
No locals.

#14 0x00000000080c6ba3 in __call (this=0x7ffff41df130, __args=...) at /usr/include/c++/7/functional:467
No locals.
#15 0x00000000080c0bd3 in operator() (this=0x7ffff41df130) at /usr/include/c++/7/functional:551
No locals.
#16 0x00000000080b9bb8 in _M_invoke (__functor=...) at /usr/include/c++/7/bits/std_function.h:316
No locals.
#17 0x0000000008055400 in operator() (this=0x8976eb0) at /usr/include/c++/7/bits/std_function.h:706
No locals.
#18 0x0000000008054f2a in operator() (this=0x8976ea0) at /ubuntu18/TFS-Master/src/tasks.h:40
No locals.

#19 0x0000000008055158 in Dispatcher::threadMain() (this=0x86efa40 ) at /ubuntu18/TFS-Master/src/tasks.cpp:60
        task = 0x8976ea0
        taskLockUnique = {_M_device = 0x86efa58 , _M_owns = false}

#20 0x00000000081230ab in __invoke_impl (__f=@0x8982fb0: (void (Dispatcher::*)(struct Dispatcher *)) 0x8055044 , __t=@0x8982fa8: 0x86efa40 ) at /usr/include/c++/7/bits/invoke.h:73
No locals.
#21 0x0000000008121ede in __invoke (__fn=@0x8982fb0: (void (Dispatcher::*)(struct Dispatcher *)) 0x8055044 , __args#0=@0x8982fa8: 0x86efa40 ) at /usr/include/c++/7/bits/invoke.h:95
No locals.
#22 0x0000000008129e95 in _M_invoke (this=0x8982fa8) at /usr/include/c++/7/thread:234
No locals.
#23 0x00000000081299f8 in operator() (this=0x8982fa8) at /usr/include/c++/7/thread:243
No locals.
#24 0x00000000081294cc in std::thread::_State_impl > >::_M_run() (this=0x8982fa0) at /usr/include/c++/7/thread:186
No locals.

#25 0x00007ffffd49d66f in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#26 0x00007ffffd7776db in start_thread (arg=0x7ffffbd80700) at pthread_create.c:463
        pd = 0x7ffffbd80700
        now = 
EPuncker commented 4 years ago

@Oen44 do https://github.com/otland/forgottenserver/commit/b99a1b507ac0dec2b4b50f3fdb8a357bb2c8733e fixes the crash?

Oen44 commented 4 years ago

@Oen44 do b99a1b5 fixes the crash?

Yeah, that fixed crashing.