Ok, just triggered the same bug. Same line of code, same vars... Also on the web version if that makes any difference.
Tought me to look up how to save this game :)
I was able to reproduce this bug.
It appears when selecting the last inventory slot.
After crafting an item, the slot disappears. The crafted item should already be in the inventory.
This only occurs when using a workbench, furnace, etc., since the active slot in these cases doesn't move to the first slot but remains at the end of the inventory, which apparently indicates empty data.
Simply put, the last slot is used in crafting and is completely emptied, but after it, a new slot is not created