Skip to content

Fix crash when trying to craft a banana - #695

Open
anankex wants to merge 1 commit into
Attnam:masterfrom
anankex:fix-banana-craft-crash
Open

anankex wants to merge 1 commit into
Attnam:masterfrom
anankex:fix-banana-craft-crash

Conversation

@anankex

@anankex anankex commented Nov 6, 2026

Copy link
Copy Markdown

Fixes #570.

Typing "banana" at "What do you want to try to create?" crashes the game instead of printing "You never learned how to cook a banana!".

CreateItemToCraft() spawns a prototype and calls EmptyContainer(), which calls the virtual RemoveSecondaryMaterial(). banana overrides that method with the eating logic. It moves its main material into a new bananapeels, sets its own main material to null and calls SendToHell(). Back in srpForgeItem::work(), GetName(INDEFINITE) reaches object::AddRustLevelDescription() and dereferences the null main material.

The fix calls materialcontainer::RemoveSecondaryMaterial() directly. The prototype then loses its contents and keeps its main material.

holybanana derives from banana, inherits the override and crashed the same way. No other class in the materialcontainer hierarchy overrides RemoveSecondaryMaterial().

CreateItem() calls EmptyContainer() for wishes that contain "empty", so a wish for an empty banana probably takes the same path. I did not test that one.

I tested on a Linux build of the v060 source with AddressSanitizer. proto.cpp is the same on master.

  • Before the patch, the game segfaults when I type banana or holy banana in the craft menu (f, then "create an item"). The backtrace goes through srpForgeItem::work() to object::AddRustLevelDescription().
  • After the patch, the same steps print "You never learned how to cook a banana!" and "You never learned how to cook the holy banana of Oily Orpiv!", and the game keeps running. AddressSanitizer didn't report anything during that session.

CreateItemToCraft() empties a material container by calling the virtual
RemoveSecondaryMaterial(). banana overrides it with the eating logic:
the banana turns into banana peels, drops its main material and sends
itself to hell. The crafting code then builds the "You never learned
how to cook" message from an item whose main material is null and
crashes in object::AddRustLevelDescription().

Call materialcontainer::RemoveSecondaryMaterial() directly. The
prototype then keeps its main material and only loses its contents.

Fixes Attnam#570
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when trying to craft a banana

1 participant