[Optics] Fixes Beamsplitter Beam Duplication
Created by: N3X15
Executive Summary
Fixes #12077 (closed), a severe exploitable issue that leaves beams floating around after a beam to a beamsplitter is interrupted. This can result in free energy and crashes, and also causes some runtime errors.
Analysis
This ended up being a fucking mess, and it looks like the underlying cause is a problem with BYOND's GC: When a list index is set from non-null to null, BYOND removes that position for some FUCKING reason. In the case of the mirror, which requires everything to stay in their assigned positions, it results in the following sequence of events:
- Mirror nukes a beam because it's no longer needed.
- GC nukes that position in the list because it is retard fuckstupid.
- Beam in the position above falls to the position just nuked.
- Loop continues.
- Loop runs into the end of the list because the list size changed from 4 to 3 and triggers a runtime and jumps out of the update process.
- Players figure out they can stack beams and get jiggawatts of juice and even negative energy.
Testing Apparatus
Just to show I did test this, the following in test_tiny.dmm is what I used to test the bug.
Changelog
- bugfix: Fixed a series of bugs and exploits involving mirrors. WE RESPECT THE LAW OF THERMODYNAMICS IN THIS HOUSE.