Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] float marked as array allocation #33

Closed
loosegrid opened this issue Apr 12, 2021 · 6 comments
Closed

[Bug] float marked as array allocation #33

loosegrid opened this issue Apr 12, 2021 · 6 comments
Labels
invalid This doesn't seem right

Comments

@loosegrid
Copy link

loosegrid commented Apr 12, 2021

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 mtrive changed the title float marked as array allocation [Bug] float marked as array allocation Apr 12, 2021
@mtrive
Copy link
Contributor

mtrive commented Apr 12, 2021

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
Copy link
Author

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
Copy link
Contributor

mtrive commented May 5, 2021

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

@loosegrid
Copy link
Author

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
Copy link
Contributor

mtrive commented May 6, 2021

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.

@mtrive mtrive closed this as completed May 6, 2021
@mtrive mtrive added the invalid This doesn't seem right label May 6, 2021
@loosegrid
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants