Unity-Technologies / ProjectAuditor

Project Auditor is an experimental static analysis tool for Unity Projects.
Other
822 stars 68 forks source link

[Bug] float marked as array allocation #33

Closed loosegrid closed 3 years ago

loosegrid commented 3 years ago

The following code gives a critical array allocation warning for each line:

//inside a for loop
Rect aabb = Rect.zero;
aabb.x = Mathf.Min(0.5f, camMin.x, camMax.x, camCenter.x);    //the three other arguments are all Vector2's
aabb.y = Mathf.Min(0.5f, camMin.y, camMax.y, camCenter.y);
aabb.xMax = Mathf.Max(0.5f, camMin.x, camMax.x, camCenter.x);
aabb.yMax = Mathf.Max(0.5f, camMin.y, camMax.y, camCenter.y);

Moving the 0.5f into a variable continues to give an error. Moving the variable outside the loop and changing it to a class constant still generates the errors, which are once again marked critical.

mtrive commented 3 years ago

Hi @Appleguysnake, So if I understand correctly you are reporting that after editing the file, the reported issues are no longer marked as "critical". Is that correct?

loosegrid commented 3 years ago

Apparently not! I just tried to reproduce it and it seems the errors are always marked critical, I think the little icon just didn't pop up right away the first time I tested it.

mtrive commented 3 years ago

@Appleguysnake, Is it safe to close this issue then?

loosegrid commented 3 years ago

No, being marked as critical was just an extra detail. The bug is that floats are not arrays so it shouldn't be flagging them as array allocations.

mtrive commented 3 years ago

Indeed they are all float but they are all packed together into an array. It's using Mathf.Min method with params keyword. public static float Min(params float[] values)

It's an implicit array allocation.

loosegrid commented 3 years ago

Ahhh okay I see now, thanks for explaining it. Perhaps there's a way to clarify the message in that case?