Fixed segfault when monster tries to grab-drag another monster out of reality bubble #76058
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 "Fixed segfault when monster tries to grab-drag another monster out of reality bubble"
Purpose of change
fix #75793
I believe, someone was writing the code for selecting a random square, then discovered that function
random_entry
already exists and decided to use it instead, but forgot to remove already written and no longer needed codeThere are 2 lines of code at mattack_actors.cpp:617
Those lines are optimized away by some configs since variable
intersect_iter
is never used after thisset
intersect
is not checked for being empty.intersect
is empty when monster that does dragging is right at the edge of reality bubble and the next tile in the direction of dragging is outside of it.when
intersect
is empty second line causes segfault (if built for linux using gcc or built for windows using mxe) or debug assetion failure "cannot decrement begin map/set iterator" (if built using msvc for debugging)this crash does not occur in android and msvc-release builds
function
random_entry
called on the next line after those 2 hascontainer.empty()
check, 2 same lines and return of it is assigned totarget_square
and actually used down the codeDescribe the solution
remove redundant code
Describe alternatives you've considered
Testing
Compiled, verified that monsters can grab and drag and save from linked issue does not trigger segfault
Additional context
Should be backported to 0.H-branch since those lines are present there