new Texture2D() creates three GC allocations in total in Development build. Like this.
Two of them stem from SupportsTextureFormat which is internally used in Texture2D constructor.
We can see SupportsTextureFormat causes problem just by calling it like below.
This is entirely from bad C# code in Unity and should be avoided.
Edit: Maybe I should mention what “bad” is. Boxing of enum causing it. Bad.
Third allocation is something I did not check where it from. Maybe new itself?
This problem became serious to me when I have written custom solution for loading assets.
Help me Unity guys;(
I put the culprit here just to clarify how sad this is.
// The enums are only marked as obsolete in the editor.
/// <summary>
/// Determine if enum value is obsolete.
/// If multiple enum members refer to the same value,
/// the value is considered obsolete if all members are marked obsolete.
/// </summary>
internal static bool IsEnumValueObsolete(Enum value)
{
foreach (var enumMember in value.GetType().GetFields(BindingFlags.Static | BindingFlags.Public))
{
if (!object.Equals(enumMember.GetValue(null), value)) continue;
var isObsolete = enumMember.GetCustomAttributes(typeof(ObsoleteAttribute), false).Length != 0;
if (!isObsolete)
{
return false;
}
}
return true;
}
static bool IsValidEnumValue(Enum value)
{
if (!Enum.IsDefined(value.GetType(), value))
return false;
if (IsEnumValueObsolete(value))
return false;
return true;
}
SupportsTextureFormat using these with boxing.
At the very least, we need an option to avoid this weird safety check.
Maybe I have to use dnspy to obliterate it in the meantime? I do not know it is allowed or not though.
But even if it is, it gonna be flipping tough because different dlls used for editor and runtime.
Can I call this a bug without confirming by officials?
This is, well, let’s just say horrible but maybe not a bug as at least it does its job as expected.
I thought bug report was only possible when officials ask us to do so.
I’ve done reporting once very recently because they told me to do so. Processing takes long and it seems serious. I feel like if many amateurs send their unreliable repporting at their will as Bug Report, it would give Unity a load of stress.
TBW paying money to them and “having to” report easy bugs makes no sense. May sounds harsh though. I’m not paid for it.
Reporting takes time as a reporter. I don’t have that much time.
Edit: I thought reporting must be done with reproducible project attached but maybe not? If so easy thing can be reported more easily.
This time I decided to ignore this issue by using dnSpy as I’ve already done that.
Anyway, now I understand easy problem like this should not be reported here. I am not going to use Bug Reporter neighter, though.
What I meant by saying that is I do not want to report this specific incident as a bug because I am lazy now. That is all. Sorry.
But thank you for teaching me the usual process. I initially recognize this is not a bug though.
Edit: I’m not going to do anything about this as I’ve already sorted it out for me. And I do not appear in this thread anymore. If you care this problem, please do bug report instead.
You take the trouble to investigate the problem: profiling, look for the source code in github, …
They tell you to report it or else this thread will be forgotten. You have almost a repro project with your first post and your answer is “I don’t have time and it’s not my job”.
You solve your problem, you do not provide useful information for someone in your same situation and on top of that you are rude answering that you will not post more here and that we are the ones to report it.
Thank you for summarizing:) Very kind of you. What a civilized world.
Well sorry, now I stop being sarcastic. I just decided to apologize sincerely and reappear here.
I just intentionally decided not to do anything useful in this therad, you surely have already noticed. Sorry about this.
Things went wrong when I just irritated with TJHeuvel-net. I felt like being pused too hard. Maybe I just am not good at English though. Or just I easily get annoyed.
Yes I am a jerk, but you guys really ought to know how to communicate each other more peacefully, too. (Somebody said fish and human can coexist peacefully:) But seems humans cannot.) I am sure this is exactly what you guys do not want to hear from ME… But after a few post, I now be condemned so badly. Yes I am rude but It is mutual in some capacity. Not that funny.
Basically not all people are keen to contribute to Unity. Of course it is not duty nor something so important. Community is supported by charitable people decided to do so. I know you guys are too. But you should be a little bit more patient and try to support newbies more carefully to grow the community for the greater good. I am a newbie here, too.
Anyway, if I should do, I will report when I have time. Maybe at this point someone else has done that? If not I will do.