Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game freeze when telling NPC to construct woodchip floor in basecamp #41220

Closed
Yunatan opened this issue Jun 10, 2020 · 6 comments · Fixed by #46286
Closed

Game freeze when telling NPC to construct woodchip floor in basecamp #41220

Yunatan opened this issue Jun 10, 2020 · 6 comments · Fixed by #46286
Assignees
Labels
<Bug> This needs to be fixed Code: Performance Performance boosting code (CPU, memory, etc.) Crafting / Construction / Recipes Includes: Uncrafting / Disassembling NPC / Factions NPCs, AI, Speech, Factions, Ownership
Milestone

Comments

@Yunatan
Copy link
Contributor

Yunatan commented Jun 10, 2020

Describe the bug

I ordered my NPC to build a woodchip floor, then the game stalled and froze. No errors, no crashed, just eternal lag. I had some performance issues around my basecamp for some time prior to this due to sheer amounts of loot, but nothing too serious.

Steps To Reproduce

  1. Load the attached save backup.
  2. Tell NPC to make woodchip floor outside
    2.1 Open Zone manager (Y)
    2.2 Add new zone (A)
    2.3 Choose "Construction: Blueprint" (4)
    2.4 Choose"Make Woodchip Floor" (never mind that requirements are red)
    2.5 Designate a one tile zone on the snow near the player, save changes
    2.6 Talk to NPC standing next to the player (Leila 'Charm' Weir, prisoner)
    2.7 Talk about current activity (i), then do construction work (d)
  3. Wait 5 minutes
  4. Game freezes

Expected behavior

Game is not freezing and NPC works on woodchip floor if able.

Versions and configuration

  • OS: Windows
    • OS Version: 10.0 1809
  • Game Version: 0.E-1 [64-bit]
  • Graphics Version: Tiles
  • Game Language: English [en]
  • Mods loaded: [
    Dark Days Ahead [dda],
    No Rail Stations [No_Rail_Stations],
    Graphical Overmap [Graphical_Overmap]
    ]
@Yunatan Yunatan changed the title Game freeze when telling NPC to construct woodchip floor around basecamp Game freeze when telling NPC to construct woodchip floor in basecamp Jun 10, 2020
@anothersimulacrum anothersimulacrum added <Bug> This needs to be fixed Code: Performance Performance boosting code (CPU, memory, etc.) Crafting / Construction / Recipes Includes: Uncrafting / Disassembling NPC / Factions NPCs, AI, Speech, Factions, Ownership labels Jun 10, 2020
@anothersimulacrum
Copy link
Member

I can reproduce on experimental - it's not quite a complete freeze, but when the NPC starts to move woodchips, it gets quite slow, and freezes a bit.

@ZhilkinSerg ZhilkinSerg added this to the 0.F milestone Aug 18, 2020
@Aivean
Copy link
Contributor

Aivean commented Nov 21, 2020

Can somebody please recheck this issue in latest experimental?

I'm noticing a tiny bit of lag every 5-10 in-game minutes, but not even close to the scale described in the issue.

The lag comes from inventory::add_item I'll look into it anyway, but I'm not sure if I'm missing something.

@esotericist
Copy link
Contributor

esotericist commented Dec 14, 2020

loading this in a recent (as of a couple days ago) debug build, my experience is that during the process of relocating the splintered wood for the construction task, performance plummets viciously.

turns which were going by pretty close to instantly previously (again, actual debug build, not merely with debug symbols) were taking up to three seconds, and it was taking sometimes multiple turns to move each individual splintered wood.

once all the splintered wood was moved and the npc moved on to a different task, things resumed being swiftly responsive.

the impact here is substantial, and i don't experience the same degree of slowdown having the same NPC in the same save moving items around from sorting loot. i think there's definitely an issue in the collecting-stuff-for-construction task.

@esotericist
Copy link
Contributor

a key factor to the reproduction process here that needs to be noted is: starting a construction for the woodchip floor requires digging a pit first, which the system helpfully automatically handles before moving on to the floor construction. the problematic behavior will not be exhibited until after a pit is made, and the NPC decides to collect the materials to actually construct the floor.

@Aivean
Copy link
Contributor

Aivean commented Dec 19, 2020

Ok, I finally managed to reproduce it:
image

The game indeed becomes frozen. Seems that the issue is with temporary crafting inventory copying items.

@Aivean Aivean assigned Aivean and unassigned mlangsdorf Dec 19, 2020
@Aivean
Copy link
Contributor

Aivean commented Dec 22, 2020

Ok, so I did a bit of debugging, and there are two problems here.

First, there is an actual freeze (infinite loop) that is caused by ACT_FETCH_REQUIRED failing this check:

// we checked if the work spot was in darkness earlier
// but there is a niche case where the player is in darkness but the work spot is not
// this can create infinite loops
// and we can't check player.pos() for darkness before they've traveled to where they are going to be.
// but now we are here, we check
if( activity_to_restore != ACT_TIDY_UP &&
activity_to_restore != ACT_MOVE_LOOT &&
p.fine_detail_vision_mod( p.pos() ) > 4.0 ) {
p.add_msg_if_player( m_info, _( "It is too dark to work here." ) );
return false;
}

It's trivial to fix, I'll submit PR soon.


And there is a second issue, the NPC construction AI performance. The issue lies in are_requirements_nearby using inventory to validate requirements, which is incredibly slow:
image

I'm evaluating some ideas on how to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bug> This needs to be fixed Code: Performance Performance boosting code (CPU, memory, etc.) Crafting / Construction / Recipes Includes: Uncrafting / Disassembling NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants