CleverRaven / Cataclysm-DDA

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

Activating worn collapsed telescoping umbrella crashes the game #72111

Open AnotherSeawhite opened 6 months ago

AnotherSeawhite commented 6 months ago

Describe the bug

Activating worn collapsed telescoping umbrella crashes the game.

Attach save file

Test-trimmed.tar.gz

Steps to reproduce

  1. Wear a collapsed telescoping umbrella.
  2. Activate it.

Expected behavior

I expected the character to either: refuse activating it automatically wield it have an umbrella integrated into the body and not crash

Screenshots

No response

Versions and configuration

Additional context

crash.log

RenechCDDA commented 6 months ago

Unable to reproduce on MSVC build

image

Your uploaded save appears to be corrupted, it downloads as a 0KB file. Please try uploading it again, there may be other conditions required to induce the crash.

RenechCDDA commented 6 months ago

That said, the likely problem appears to be here:

index 7eee88c9ba..9938bb706d 100644
--- a/src/iuse_actor.cpp
+++ b/src/iuse_actor.cpp
@@ -265,6 +265,10 @@ std::optional<int> iuse_transform::use( Character *p, item &it, const tripoint &
         }
     }

+    if( it.is_tool() ) {
+        result = scale;
+    }
+
     if( it.count_by_charges() != target->count_by_charges() && it.count() > 1 ) {
         item take_one = it.split( 1 );
         do_transform( p, take_one, variant_type );
@@ -273,9 +277,6 @@ std::optional<int> iuse_transform::use( Character *p, item &it, const tripoint &
         do_transform( p, it, variant_type );
     }

-    if( it.is_tool() ) {
-        result = scale;
-    }
     return result;
 }

It's checking is_tool() on it (the item to be transformed) after the item has been transformed. The item no longer exists, game explodes.

This patch simply moves the check to before the transformation, when we know the item still exists.

AnotherSeawhite commented 6 months ago

Is it corrupted? Aw man, I hate Android sometimes. I'll try to upload it again when I get back home.