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

Prevent character from being Dead on Arrival. #36489

Conversation

kevingranade
Copy link
Member

Summary

SUMMARY: None

Purpose of change

In #36470 a fix to avoid undefined behavior resulted in leaving characters in a bad state upon character creation, namely their max HP was pinned to 0.

Describe the solution

Instead of skipping the code where undefined behavior was occurring (seriously, this is never a good idea!), add code to insure that the desired semantics are preserved even when max_hp for a body part happens to be 0.
Also initialized max_hp for all body parts to 1 instead of 0, and patched another location where max_hp was potentially 0 to instead floor it at 1.

Testing

The NPC behavior test no longer crashes.
You can now spawn a character without them immediately dying.

Additional context

Since this is one of the few classes of bugs that makes the game literally unplayable, I'm going to merge this once the test suite completes.

Hope this is the last time
'cus we never should've merged this code
This character has been, dead. on. arrival.
And there's no way to play this game
This character has been, dead. on..

A rivalry goes so deep between me
And this loss of sleep over bugs

This is patch one
Merge it real fast
I know this ain't your favorite bugfix
The games you grow to like, never stick at first
So I'm writing you a bugfix
And here's a release

No, it's not the last time
'cus we'd never close your PR
This character is still, dead. on. arrival.
And there's no way to play this game
This character has been, dead. on..

A rivalry goes so deep between me
And this loss of sleep over bugs

This is patch one
Merge it real fast
I know this ain't your favorite bugfix
The games you grow to like, never stick at first
So I'm writing you a bugfix
And here's a release

This is patch one
Merge it real fast
I know this ain't your favorite bugfix
So-o-o-o

This is patch one
Merge it real fast
This is patch one
Merge it real fast
I know this ain't your favorite bugfix
The games you grow to like, never stick at first
So I'm writing you a bugfix
And here is your...

@ZhilkinSerg ZhilkinSerg added (P1 - Critical) Highest priority (for ex. crash fixes) <Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world labels Dec 27, 2019
@ZhilkinSerg
Copy link
Contributor

Fixes #36487

@kevingranade
Copy link
Member Author

This pull request has been mentioned on Cataclysm: Dark Days Ahead. There might be relevant details there:

https://discourse.cataclysmdda.org/t/instant-death-on-generation/22314/3

@hexagonrecursion
Copy link
Contributor

I have learned my lesson: compiling C++ is SLOW, but the alternative is INFINITELY WORSE. Also: cool poem.

@kevingranade kevingranade deleted the avoid-undefined-behavior-without-killing-yourself branch June 28, 2020 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world (P1 - Critical) Highest priority (for ex. crash fixes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants