Fix a bug that could freeze up a weapon and even the simulation #6345
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the proposed changes
Related to this forum post and this Discord post.
Weapons now properly use the
AttackGroundTries
field because of #6277. For the average unit this is fine, but for bombers and specifically bombers with multiple projectiles per salvo it introduced an unusual problem: the first projectile would aim at the current target. All remaining projectiles may aim at the next target. This doesn't apply to all bombers, but in particular the UEF Tech 1 bomber (Scorcher) fell victim to this bug.When the bug happens we end up in an unstable state. To the user this would show as:
These issues are related to how we re-compute the (vertical) bomb trajectory in Lua. We do this in Lua to fix an engine bug where bombers would constantly miss their target. For a salvo the code assumes that the ground target does not suddenly shift as the salvo is being processed. This is a safe assumption as any normal interrupt would also cancel the salvo. But now that the engine can use the
AttackGroundTries
field again it is suddenly very possible that this happens throughout the salvo. And as a result the computations are all messed up. And because of that we try to get the square root of a negative number. This imaginary number does not exist in the real world and since we simulate the real world here (ha) the game returns an invalid number:-1.#ND
.This introduces all sorts of problems. One of them is (1). The other is (2) as we pass the invalid number to
SetBallisticAcceleration
. The moment that happens the simulation freezes.Testing done on the proposed changes
Spawn in various bombers and make them bomb random patches of ground.
Additional context
The behavior of the Scorcher is consistent between FAForever and Steam - for some odd reason the Janus works as expected and the Scorcher appears to switch targets too soon. Could it be because it is the primary weapon of the Scorcher?
Checklist