Return-To-The-Roots / s25client

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

savegame crashes #1520

Closed Spikeone closed 6 months ago

Spikeone commented 2 years ago

This is a savegame of a scripted map - it always crashes after some GF. Not sure what the cause is, the console does not indicate a LUA error.

4.zip WORLDS.zip

Spikeone commented 2 years ago

Replay is also crashing: 2022-04-10_23-33-01.zip

Just checked by running from visual studio, this doesn't seem to be related to LUA scripting but a more general problem which I do not fully understand :-/

wichern commented 6 months ago

I think what happens here, is that there is a flag at 88,7. When loading the savegame, MissionEvent(e=1) is triggered, which adds a static object of size 2. rttr:GetWorld():AddStaticObject(89, 8, 560, 0xFFFF, 2)

This causes the removal of the flag. Unfortunately, at that moment there is already a worker carrying something to that flag. When he reaches it and wants to place his goods, we have a nullptr dereference.

The lua doc says e=1 is an initial event. I guess this should only be called when the game starts and not on every loading of a savegame.

Spikeone commented 6 months ago

Good find @wichern I guess - never understood the stack trace correctly.

I'm still confused since when having a look at the script, from the very beginning MissionEvent(1) has been called. That means rttr:GetWorld():AddStaticObject(89, 8, 560, 0xFFFF, 2) should work just fine - since an object should block all the space it requires. Although the MissionEvent(99) calls rttr:GetWorld():AddStaticObject(89, 8, 561, 0xFFFF, 2) as well, this shouldn't be a problem.

So maybe for this bug here, the root cause then is #1516 - maybe roads are removed when placing the object, but spots are not blocked correctly, thus leading to the crash.

wichern commented 6 months ago

The build locations for portals are strange. And they get even stranger, when building/removing stuff around them. Seems they bend time and space :) Screenshot from 2024-02-27 18-51-15 Screenshot from 2024-02-27 18-51-20 Screenshot from 2024-02-27 18-51-25 Screenshot from 2024-02-27 18-51-32

I tried with this change, and it seems to solve the issue of adding building quality by just removing/adding things. I did not really understand what happens though.

Screenshot from 2024-02-27 18-27-37 Screenshot from 2024-02-27 18-57-09

Flamefire commented 6 months ago

I tried with this change, and it seems to solve the issue of adding building quality by just removing/adding things. I did not really understand what happens though.

Screenshot from 2024-02-27 18-27-37

This might actually be 2 different issues, depending on what we want as the end result. If your third image is the correct BQ then this part of the code must not change. I think the issue is that not enough BQ points are updated when the object is placed. So we need to update more at https://github.com/Return-To-The-Roots/s25client/blob/12f0c5fbb5ab130dc43172519ebcfbb511222509/libs/s25main/lua/LuaWorld.cpp#L87 possibly depending on the size (0=no call, 1= current call, 2=RecalcBQAroundPointBig, maybe just no or RecalcBQAroundPointBig)
The castle-like blocking behavior is achieved by "noExtension" instances: https://github.com/Return-To-The-Roots/s25client/blob/12f0c5fbb5ab130dc43172519ebcfbb511222509/libs/s25main/nodeObjs/noStaticObject.cpp#L35

Spikeone commented 6 months ago

probably fixed by #1647 - thanks to @wichern