Fixes SegFault w/ flashlights & attached power #78633
Open
+12
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Bugfixes "Fixes SegFault w/ flashlights & attached power"
Purpose of change
There was a segfault occuring on
Cataclysm-DDA/src/item.cpp
Line 12277 in de687d3
Describe the solution
Added:
case there are any other edge cases where this occurs.
power source's linked power when determining the illumination value.
Describe alternatives you've considered
I didn't consider any other alternatives.
Testing
I loaded CDDA in a dev environment prior to this fix and created a test world and saved it once I had the conditions necessary to reproduce the bug. In that test world, I then turned on the flashlight and successfully reproduced the bug.
After applying the fix, I loaded the same save and attempted the same action. This time successfully due to the fix. In addition, I spawned a normal vehicle, attached the flashlight to it, and ensured there was a power draw occurring (there was). Then I removed the battery while the flashlight was on to ensure that it both turned off (it did) and that the game did not crash (it did not).
Additional context
I used
Cataclysm-DDA/src/item.cpp
Line 14177 in de687d3
has_link_power
that returns a boolean (true for has power, false otherwise). My only hesitation is that I do not know where else that sort of power check is done and what the complete scope of the checks againstcharge_rate
/charge_interval
are for.