CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.61k stars 4.17k forks source link

Segmentation fault crash to desktop while picking up items #65166

Closed KHeket closed 6 months ago

KHeket commented 1 year ago

Describe the bug

When I am trying to pick up my weilding items - crash happends. It happen for me for a few times before while looting, but this crash I can reproduce

Attach save file

1-trimmed.tar.gz

Steps to reproduce

1) Load the save file 2) Pick up by "g" all items in the tile with wielding items (see screenshot)

Pick up all items in this tile ![image](https://user-images.githubusercontent.com/102726167/232837357-a5f7bda8-c209-4786-8bc4-0277a333a56e.png) ![image](https://user-images.githubusercontent.com/102726167/232837599-b0f0ce03-9525-4e1d-9602-5cd9c99ffd3d.png)

3) See segmentation fault crash to desktop

Crash screenshot ![image](https://user-images.githubusercontent.com/102726167/232837822-de92ebde-bbe5-4497-996d-59467be16e8c.png)

Expected behavior

No crash

Screenshots

No response

Versions and configuration

Additional context

crash.log debug.log

katemonster33 commented 1 year ago

Could not reproduce the error on latest master, the pickup window does not allow you to select the arc welders, saying "does not fit in inventory"

RenechCDDA commented 1 year ago

/confirmed

(You need dangerous pickups turned on to pick up the arc welders, since that takes them over the weight limit. Crashes even when picking up the welding wires though)

Dropping the two military rucksacks contained in the high-volume rucksack they're wearing seems to avoid the crash, and the stack trace suggests it's pocket related.

RenechCDDA commented 1 year ago

Okay... and this doesn't crash when I compile master in visual studio 2019.

I'm guessing this is one of those compiler-specific bugs?

andrei8l commented 1 year ago

item_pocket::better_pocket() doesn't satisfy Compare. The effect of that failure is implementation-dependent.

Potential patch:

diff --git a/src/item_pocket.cpp b/src/item_pocket.cpp
index 3ca17aa011..b50f2bfd36 100644
--- a/src/item_pocket.cpp
+++ b/src/item_pocket.cpp
@@ -382,14 +382,14 @@ bool item_pocket::better_pocket( const item_pocket &rhs, const item &it, bool ne
         return false;
     }

-    if( rhs.data->extra_encumbrance < data->extra_encumbrance ) {
+    if( rhs.data->extra_encumbrance != data->extra_encumbrance ) {
         // pockets with less extra encumbrance should be prioritized
-        return true;
+        return rhs.data->extra_encumbrance < data->extra_encumbrance;
     }

-    if( data->ripoff > rhs.data->ripoff ) {
+    if( data->ripoff != rhs.data->ripoff ) {
         // pockets without ripoff chance should be prioritized
-        return true;
+        return rhs.data->ripoff < data->ripoff;
     }

     if( data->rigid != rhs.data->rigid ) {

So there were cases where lhs < rhs due to ripoff AND same rhs < lhs due to remaining volume a bit below.