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: fixes crash when fertilizing crops #4932

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

irontofu1
Copy link
Contributor

@irontofu1 irontofu1 commented Jul 4, 2024

Checklist

Required

Purpose of change

Fixes #4446. Verify by attempting to fertilize any planted crop, which would previously cause a seg fault and crash the game.

Describe the solution

I believe this was caused by the order of the code in iexamine::fertilize_plant. I'm skipping some of the steps, but the relevant ones were in this order before: get a pointer to the seed item being fertilized -> spawn fertilizer item on that tile (so it can only be fertilized once) -> use seed pointer to format a game message with the proper plant name. I think that spawning the fertilizer would invalidate the seed pointer and cause the seg fault when trying to get its name. I just changed the order so that the fertilizer is spawned before we use the iterator to get the seed pointer.

Describe alternatives you've considered

Still new to C++ so this was the only solution I could come up with. I'm more than open to others but this felt like the safest way to fix the issue without breaking something else.

Testing

Fertilized several crop types (wheat, tomatoes, beans) with both commercial and liquid fertilizer. No crash. Was still only able to fertilize each tile once.

Additional context

@github-actions github-actions bot added the src changes related to source code. label Jul 4, 2024
@chaosvolt chaosvolt changed the title Fixes seg fault crash when fertilizing crops (#4446) fix: fixes seg fault crash when fertilizing crops (#4446) Jul 4, 2024
@irontofu1 irontofu1 changed the title fix: fixes seg fault crash when fertilizing crops (#4446) fix: fixes crash when fertilizing crops Jul 4, 2024
@chaosvolt chaosvolt merged commit 1f051e7 into cataclysmbnteam:main Jul 4, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
src changes related to source code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation Fault crash on trying to fertilize the plant
2 participants