Opened 3 years ago

Closed 3 years ago

#5852 closed defect (fixed)

Dot product overflow in CCmpUnitMotion

Reported by: Itms Owned by: wraitii
Priority: Must Have Milestone: Alpha 24
Component: Core engine Keywords:
Cc: Patch: Phab:D3061

Description

I am not sure this has an actual impact on gameplay, but there is an overflow happening in the unit motion component (at least under r24041).

It can be reproduced by running the attached commands.txt under r24041 in Debug mode (Release mode ignores these overflows).

Relevant call stack:

>	pyrogenesis_dbg.exe!CFixedVector2D::Dot(const CFixedVector2D & v) Line 216
>	pyrogenesis_dbg.exe!CCmpUnitMotion::ComputeTargetPosition(CFixedVector2D & out, const CCmpUnitMotion::MoveRequest & moveRequest) Line 1152
>	pyrogenesis_dbg.exe!CCmpUnitMotion::ComputeGoal(PathGoal & out, const CCmpUnitMotion::MoveRequest & moveRequest) Line 1330

Change History (3)

comment:1 by wraitii, 3 years ago

Undefined behaviour afaik, so potential OOS.

I can reproduce on basically any map by ordering a unit to attack a moving unit across the map.

Dot() is actually an overflow-nightmare. With vectors as low as 100x, 600y, it widely overflows (fixed can only represent up to 32768). Most of the in-game code seems to be for very small scales, which ought to be fine in most cases.

I'll divide both vectors to lower their magnitude and add a warning that Dot() overflows quickly.

comment:2 by wraitii, 3 years ago

Milestone: BacklogAlpha 24
Patch: Phab:D3061
Priority: Should HaveMust Have
Status: assignednew

comment:3 by wraitii, 3 years ago

Resolution: fixed
Status: newclosed

In 24152:

Avoid overflow in UnitMotion.

ComputeTargetPosition called Dot() with large enough vectors that it overflowed. Avoid that by not actually doing the full dot product.

Reported by: Itms

Fixes #5852

Differential Revision: https://code.wildfiregames.com/D3061

Note: See TracTickets for help on using tickets.