Closed x-qq closed 2 months ago
/confirmed Detailed backtrace and repro: https://github.com/CleverRaven/Cataclysm-DDA/issues/75331#issuecomment-2276780966
It crashes in npcmove.cpp operation npc::wont_hit_friend at the creation and assignment of "dispersion" because it.ammo_data() returns a null pointer. As in the referenced report, "it" is a crossbow, and it appears item::ammo_data returns a null pointer (that's what the debugger says, and sometimes it doesn't lie).
The code would have to account for this possibility in some way, as that's a legal return value for the ammo_data operation. I don't know why ammo_data would be missing, and thus what conditions to account for (out of ammo?, something else?). If it's out of ammo you'd want to switch to another weapon rather than waiving an empty one around, but for some other cases you might want to use a default value.
I think this is something for someone who known how the ranged weapon stuff is supposed to work.
Seems to be caused by https://github.com/CleverRaven/Cataclysm-DDA/pull/75297
This looks to be the issue fixed by #75418. Your experimental version is two weeks out of date, please try upgrading and seeing if the issue persists.
No, it's unfortunately not due to an old version. Here's the version I used.
Also, the error is in a different place of the code compared to #75418.
I have tested with cdda-linux-tiles-x64-2024-08-15-1712 and it's no longer segfaulting (3 out of 3).
Still crashing when a bandit firing a crossbow.
diff --git a/src/npcmove.cpp b/src/npcmove.cpp
index a1ac030171..8b1ca0816c 100644
--- a/src/npcmove.cpp
+++ b/src/npcmove.cpp
@@ -2712,6 +2712,11 @@ int npc::confident_throw_range( const item &thrown, Creature *target ) const
// Index defaults to -1, i.e., wielded weapon
bool npc::wont_hit_friend( const tripoint &tar, const item &it, bool throwing ) const
{
+ if( it.is_gun() && it.empty() ) {
+ return true;
+ }
+
if( throwing && rl_dist( pos(), tar ) == 1 ) {
return true; // If we're *really* sure that our aim is dead-on
}
Fixed with the code above.
Describe the bug
Currently whenever there are bandits participating in any sort of combat, there is a significant probability of a segfault happening.
Attach save file
Debug-trimmed.tar.gz
Steps to reproduce
Expected behavior
No segfaults.
Screenshots
Versions and configuration
Game version: cdda-linux-tiles-x64-2024-08-03-0533, unmodified
Additional context
No response