Return-To-The-Roots / s25client

Return To The Roots (Settlers II(R) Clone)
http://www.rttr.info
GNU General Public License v2.0
470 stars 75 forks source link

crash/breakpoint in world.cpp #1674

Closed stefson closed 2 weeks ago

stefson commented 3 weeks ago

the backtrace:

Thread 1 "s25client" received signal SIGTRAP, Trace/breakpoint trap.
0x000055555573b78e in World::ReduceResource (this=<optimized out>, pt=...)
    at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/world/World.cpp:164
warning: 164    /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/world/World.cpp: Datei oder Verzeichnis nicht gefunden
(gdb) bt
#0  0x000055555573b78e in World::ReduceResource (this=<optimized out>, pt=...) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/world/World.cpp:164
#1  0x000055555562f62b in nofFisher::WorkFinished (this=0x555558945240) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/figures/nofFisher.cpp:117
#2  0x000055555562e843 in nofFarmhand::HandleDerivedEvent (this=0x555558945240)
    at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/figures/nofFarmhand.cpp:47
#3  0x0000555555742923 in EventManager::ExecuteEvents (this=this@entry=0x5555574d59d0, itEvents=...)
    at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/EventManager.cpp:141
#4  0x00005555557425bf in EventManager::ExecuteCurrentEvents (this=0x5555574d59d0)
    at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/EventManager.cpp:125
#5  EventManager::ExecuteNextGF (this=0x5555574d59d0) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/EventManager.cpp:87
#6  0x0000555555744eee in Game::RunGF (this=0x55555635a080) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/Game.cpp:77
#7  0x00005555556d04b4 in GameClient::NextGF (this=0x55555632dd10, wasNWF=<optimized out>)
    at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/network/GameClient.cpp:1402
#8  GameClient::ExecuteGameFrame (this=this@entry=0x55555632dd10) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/network/GameClient.cpp:1337
#9  0x00005555556d00aa in GameClient::Run (this=0x55555632dd10) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/network/GameClient.cpp:195
#10 0x000055555559a94b in GameManager::Run (this=0x7fffffffd700) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25main/GameManager.cpp:105
#11 0x00005555555889e7 in (anonymous namespace)::RunProgram (options=...) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25client/s25client.cpp:488
#12 0x0000555555585efb in main (argc=<optimized out>, argv=<optimized out>) at /var/tmp/portage/games-strategy/s25rttr-9999-r6/work/s25rttr-9999/libs/s25client/s25client.cpp:567

the replay: 2024-06-16_16-19-11.zip

also happened during an attack, maybe related to #1668

Flow86 commented 2 weeks ago

it crashes here: https://github.com/Return-To-The-Roots/s25client/blob/7bf8281a41e094ad1aa43d574da489a13afe1958/libs/s25main/world/World.cpp#L163-L165

so it looks like the resource point is empty?!?

Flamefire commented 2 weeks ago

I see what the problem is: nofFarmhand searches for a work point where the fisher should go by using GetPointQuality. If it found one it reserves the point such that no other figure can work there.

However for fishers they need an adjacent fish, so the point where they work (from) is not relevant.

I assume what happens:

For the animation we need to know whether it will be successful when the work starts, i.e. when the fisher arrives.

A related issue I see is that nofFarmhand doesn't check whether the point is valid when it arrives: https://github.com/Return-To-The-Roots/s25client/blob/7bf8281a41e094ad1aa43d574da489a13afe1958/libs/s25main/figures/nofFarmhand.cpp#L208-L219

That doesn't help much in this case because the point becomes invalid after the worker has arrived & started.

Solutions:

  1. Reduce the resource on arrival --> The other fisher will abort walking to the point or go back if he just arrives (if we fix the farmhand issue above
  2. Keep the farmhand issue but still reduce the resource on arrival. Then handle in nofFisher that no fish is available by searching for a random water point nearby (for drawing where to throw the rod to) and set success=False
  3. Keep as of now (maybe fix the farmhand issue) just fail if there was no more fish at the end
  4. reserve the fishing point

The first might look odd as the fisher turns around just after arrival, but he might turn around at any other point along the way either.
The 2nd is inconsistent and might hide other issues where the point becomes invalid just before/at arrival (for any farmhand).
The 3rd draws catching a fish but then produces none.
The last one disallows 2 fishers next to each other even if there is enough fish.

--> The first is the most sensible IMO. Only minor issue: If the building gets destroyed while the fisher is still fishing he aborts but the fish is lost. I'd say: Whatever!