PathOfBuildingCommunity / PathOfBuilding

Offline build planner for Path of Exile.
https://pathofbuilding.community
Other
3.99k stars 2.08k forks source link

Memory issue (crash) #3733

Closed Wyrade closed 2 years ago

Wyrade commented 3 years ago

Check version

Check for duplicates

What is the expected behaviour/value?

PoB not crashing/running out of memory.

What is the actual behaviour/value?

PoB crashing/running out of memory.

How to reproduce the issue

I tried with two character builds, so probably not buildscpecific and 100% reproducable.

  1. Hover over one of the equipped items on the "Items" page in the list of equipped items, doesn't even need to be one with multiple euippable items, one is enough
  2. Start quickly switching items with the mouse scroll up and down (switching between the item and "None" is enough)(switch at least twice per second or more - less is probably enough, but the faster the switch, the faster the crash)
  3. The memory usage starts quickly going up, 40+ MB per tick in the task manager.
  4. At around 1700 MB memory used, PoB just shuts down, showing the window seen in the attachment for about 1-2 seconds. With fast enough switching I can make it 100% consistently crash in about 15 seconds with this.

(Found this accidentally while comparing stat changes switching two items.) (PoB version 2.13.0, currently latest)

Build code

https://pastebin.com/YByttEAJ

Screenshots

PoB_crash

zao commented 3 years ago

Reproduced it with these instructions on a build of mine. Impressive 🥇

zao commented 3 years ago

Crashing under a debugger shows similar failure to most of the crash dumps in #3722: 0xC0000005: Access violation reading location 0xFFFFFFF1.

Stack trace suggests running out of memory on the Lua side:

>   SimpleGraphic.dll!@lj_err_throw@8()    C
    SimpleGraphic.dll!_lj_err_mem()    C
    SimpleGraphic.dll!_lj_BC_FUNCC()   Unknown
    00010662()  Unknown
coani commented 2 years ago

--- SCRIPT ERROR --- Runtime error in 'C:\Users\x\AppData\Roaming\Path of Building Community\Launch.lua': not enough memory

I've had these crashes a few times too

CrowdControlled commented 2 years ago

Similar crash, but script error says not enough memory.

https://imgur.com/OblK0Cr screen snip of the crash screen.

ifnjeff commented 2 years ago

I have a suspicion this may be an ever-expanding undo snapshot stack, I'm going to take a stab at having the stack store diffs rather than snapshots, and putting a cap on the height of the stack

coani commented 2 years ago

I've had 2 random pob crashes lately, in one case while tinkering with the skill tree, the other time (just now) I had inventory open and had just alt-tabbed out for 2 secs (was comparing items on trade vs mine). I had been switching between some sort orders for the uniques (sort by combined vs name), wasn't doing anything else there.

The event Viewer error is same for both crashes:

Faulting application name: Path of Building.exe, version: 0.0.0.0, time stamp: 0x606d1b4c Faulting module name: SimpleGraphic.dll, version: 0.0.0.0, time stamp: 0x61ccf697 Exception code: 0xc0000005 Fault offset: 0x0007ba01 Faulting process id: 0x34f4 Faulting application start time: 0x01d828a9fead5556 Faulting application path: C:\Users\x\AppData\Roaming\Path of Building Community\Path of Building.exe Faulting module path: C:\Users\x\AppData\Roaming\Path of Building Community\SimpleGraphic.dll Report Id: 937bbf95-a3ee-42fb-bae8-dd6ce26bba61 Faulting package full name: Faulting package-relative application ID:

ImVexed commented 2 years ago

Is there any short-term solution for this until the underlying cause is fixed? I keep coming back to this issue every few days when it crashes causing me to lose an hour or two of work every time :(

Maybe save the unsaved work any time something has changed to a temp file similar to Notepad++? Until either, it's saved properly or gracefully quit and an unsaved work popup is shown?

Fish013 commented 2 years ago

So, I've investigated this a bit further, and like @ifnjeff suspected - the undo list is growing too fast. There actually exists a cap of 100 entries. However with a pretty empty build each undo snap is already about ~5mb, so for 100 snaps we're using 500mb of ram. Even if it's pretty huge, it works if I put a garbage collect after every snapshot creation. The issue is that with scrolling we are producing the snapshots faster than the gc collects the dead elements. I've experimentally set the snapshot limit down to 10 but with fast scrolling we allocate around 220mb additional ram where the pure size of the 10 snaps is "only" around 50mb.

So the options and respective disadvantages I see:

If anyone has any other ideas feel free to add them

Wyrade commented 2 years ago

@Fish013 I have several ideas, but I'm not really a programmer, so sorry if they are unfeasible or too much effort to do:

ifnjeff commented 2 years ago

Apologies for not following up on this a while ago, I made some discoveries and attempts that might be useful, but I never arrived at a good final solution. @Fish013 is on the right track, I'll add the extra details I had found in case you or anyone else wants to see this through.

Regarding the issue: One reason for the large size of each snapshot is that some of the tables being copied have references to parts of the enormous constant data table, so we are storing the meaningful user-modified data alongside big chunks of static data. The undo handlers deep-copy their tables, so we're duplicating those huge data blocks.

I considered two solutions, both of which I got a bit stalled on because of unfamiliarity with lua, and how to get around it's odd table semantics.