Page 1 of 1

[kovarex] [0.17.23] Handcraft infinite free items

Posted: Sun Mar 31, 2019 9:25 pm
by n_slash_a
This bug is largely related to the Production Scrap mod, but the root cause might impact other things.

Steps to reproduce:
1) Attempt to handcraft multiple items (craft 5 or craft all) that only have a partial change of success (largely the production scrap mod)
2) If doing craft 5, have just enough items for 5 (craft all will use all possible items, so this step doesn't apply)
3) The game will internally figure out how many will succeed, and when an intermediate product fails, will add another craft (I'm guessing a bit on this step)
4) When the internal "add another craft" occurs, and you don't have any more items in your inventory, this will happen
5) Note that this doesn't happen every time, since it is related to probabilities

What I expect to happen:
If the craft fails, then simply don't craft it (for the craft 5, you get less than 5; for the craft all, you just get less).

What actually happens:
You get a near infinite amount. I see 4.2G, which I think is 4.2 billion, which I believe is the max value of an unsigned 32 bit integer. I suspect there is an overflow (or rather underflow) issue.

The attachment show me attempting to craft 5 filter inserters, which have an intermediate craft of a fast inserter. You can see the 4.2G fast inserters in the handcraft queue. I definitely do not have the required billions of iron, circuits, or inserters to do this.

Re: [0.17.23] Handcraft infinite free items

Posted: Mon Apr 01, 2019 1:37 am
by TruePikachu
Possibly the fix would actually be to prevent using any recipies that have a branched success rate from being used as handcrafting intermediates.

Re: [0.17.23] Handcraft infinite free items

Posted: Mon Apr 01, 2019 9:25 am
by Rseding91
TruePikachu wrote: Mon Apr 01, 2019 1:37 am Possibly the fix would actually be to prevent using any recipies that have a branched success rate from being used as handcrafting intermediates.
My thoughts as well.

Re: [0.17.23] Handcraft infinite free items

Posted: Tue Apr 02, 2019 4:37 am
by n_slash_a
I would be fine with that solution as well.

Re: [0.17.23] Handcraft infinite free items

Posted: Wed Apr 03, 2019 4:46 pm
by Zaflis
What happens if you cancel that craft, biggest item spill in the history of Factorio?

Re: [kovarex] [0.17.23] Handcraft infinite free items

Posted: Thu Apr 11, 2019 3:22 pm
by kovarex
Thanks for the report.

We can still allow recipes with branching, it just needs to have non zero minimum always (which wasn't the case here). The calculator is assuming the worst possible case, but was broken with 0. Actually I got several debug-only asserts when I was trying to perform the craft.

Fixed for the next version.

Re: [0.17.23] Handcraft infinite free items

Posted: Fri Apr 12, 2019 2:08 pm
by n_slash_a
Zaflis wrote: Wed Apr 03, 2019 4:46 pm What happens if you cancel that craft, biggest item spill in the history of Factorio?
The game froze. I waited 20 minutes and eventually killed the processes. It might have been the biggest spill, but it also might have tripped something internally and never completed.

Re: [kovarex] [0.17.23] Handcraft infinite free items

Posted: Fri Apr 12, 2019 2:08 pm
by n_slash_a
kovarex wrote: Thu Apr 11, 2019 3:22 pm Thanks for the report.

We can still allow recipes with branching, it just needs to have non zero minimum always (which wasn't the case here). The calculator is assuming the worst possible case, but was broken with 0. Actually I got several debug-only asserts when I was trying to perform the craft.

Fixed for the next version.
Thank you sir!

Re: [0.17.23] Handcraft infinite free items

Posted: Sat May 25, 2019 9:57 am
by Dave64738
Zaflis wrote: Wed Apr 03, 2019 4:46 pm What happens if you cancel that craft, biggest item spill in the history of Factorio?
Yes:
ProdScrap.png
ProdScrap.png (901.46 KiB) Viewed 4875 times
Of course the game's pretty well useless at that point because it's got all this stuff it wants to dump.

Denying intermediates seems more of a workaround to me; I'd prefer to see a solution where it sometimes works, but sometimes you just get the scraps and intermediates. You'd then try again, of course, because you did in fact want the thing you tried to craft in the first place - my need for that boiler isn't going to go away just because it got scrapped, and so that would deal with any leftover intermediates.