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

fix wont_hit_friend causing segfault #75760

Merged
merged 1 commit into from
Aug 18, 2024

Conversation

osuphobia
Copy link
Contributor

Summary

Bugfixes "npc::wont_hit_friend causing segfault"

Purpose of change

Fix #75707

Describe the solution

Prevent calling nullptr ammo_data.

Describe alternatives you've considered

Testing

Bandit firing a crossbow no longer causes segfault.

Additional context

@github-actions github-actions bot added <Bugfix> This is a fix for a bug (or closes open issue) NPC / Factions NPCs, AI, Speech, Factions, Ownership [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Aug 17, 2024
@PatrikLundell
Copy link
Contributor

So, what happens when a bandit wields an empty crossbow? Not crashing is definitely an improvement, but if the bugger just stands around doing nothing it's not a proper solution.

A guess is that it might be possible to test the behavior by giving a companion a crossbow and a single bolt, tell it to guard a position, and then spawn a zombie for it to engage.

The desired behavior should be to fire the bolt and then switch to a melee weapon. A debugger should be used to verify the changed code actually is called.

And, by the way, is this specific to crossbows? What happens when a firearm runs out of ammo?

@osuphobia
Copy link
Contributor Author

So, what happens when a bandit wields an empty crossbow? Not crashing is definitely an improvement, but if the bugger just stands around doing nothing it's not a proper solution.

A guess is that it might be possible to test the behavior by giving a companion a crossbow and a single bolt, tell it to guard a position, and then spawn a zombie for it to engage.

The desired behavior should be to fire the bolt and then switch to a melee weapon. A debugger should be used to verify the changed code actually is called.

Actually, that's what a NPC will do when the gun ran out of ammo, with or without this patch.

And, by the way, is this specific to crossbows? What happens when a firearm runs out of ammo?

Only crossbows, and the game crashes in this process only when the NPC has spare bolts in their pocket, where npc::wont_hit_friend will be called an extra time in this condtion.

I didn't find a way to deal with the superpower mentioned in #75331, which allows NPCs to reload the crossbow or shoot a revolver several times in one turn.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Aug 17, 2024
@ShnitzelX2
Copy link
Contributor

Thanks, this was indeed the problem: in #75297, I did not check for whether the weapon had ammo (my bad), and I assumed that if guns worked, then crossbows would too. I think I did verify that NPC allies wielding guns could run out of ammo, though, so it's weird that only crossbows do this.

@dseguin dseguin merged commit 9efea72 into CleverRaven:master Aug 18, 2024
28 checks passed
@osuphobia osuphobia deleted the fix_wont_hit_friend branch August 19, 2024 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault triggered by bandit attacks
4 participants