Hello!
I found a bug in unity which appears when you try to change Button’s spriteState and set pressedSprite field programmatically.
The code below:
public Button btn;
public Sprite imgPress;
// Use this for initialization
void Start () {
SpriteState ss = btn.spriteState;
ss.pressedSprite = imgPress;
btn.spriteState = ss;
}
causes an exception TypeInitializationException with 100% possibility on iOS (ver. 8.4.1, iPad2 64GB).
Works fine in editor though.
Did anybody face same problem ? Is there any known solution ? Should i report a bug to support?
Basically you just cant set pressed sprite from code if you using this:
Unity 5.5.0f3
all settings default except scripting backend - mono2x (only because it builds faster for test purposes)
test devices: iPad2 64GB or iPad mini 16GB
iOS: 8.4.1 or 10.0.2
Thanks!
Update1: there is no such exception if you use scripting backend - IL2CPP and Universal architecture, but its building sooooo long, you cant use it for testing in daily work, right ?
PS
zip with reproduce project in uploaded file
full exception stacktrace:
ExecutionEngineException: Attempting to JIT compile method 'System.Collections.Generic.GenericEqualityComparer`1<UnityEngine.UI.SpriteState>:.ctor ()' while running with --aot-only.
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
at System.Collections.Generic.EqualityComparer`1[UnityEngine.UI.SpriteState]..cctor () [0x00000] in <filename unknown>:0
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Collections.Generic.EqualityComparer`1
at UnityEngine.UI.SetPropertyUtility.SetStruct[SpriteState] (UnityEngine.UI.SpriteState& currentValue, SpriteState newValue) [0x00000] in <filename unknown>:0
at UnityEngine.UI.Selectable.set_spriteState (SpriteState value) [0x00000] in <filename unknown>:0
at TestBtn.Start () [0x00000] in <filename unknown>:0
(Filename: Line: -1)
-> applicationWillResignActive()
-> applicationDidEnterBackground()
2945482–218135–btnTest.zip (1.62 MB)