playMaker

Author Topic: IL2CPP problem with enum arrays  (Read 7247 times)

MaddestOfHatters

  • Playmaker Newbie
  • *
  • Posts: 8
IL2CPP problem with enum arrays
« on: March 31, 2015, 08:33:55 PM »
If I add the following to a PlayMaker action:

Code: [Select]
enum MyEnum { A, B, C }
public MyEnum[] enumValues;

I then get errors when loading the FSM:

Code: [Select]
Error Loading Action: TestObject : FSM : start : HutongGames.PlayMaker.Actions.MyTestAction : enumValues
Replacements.RemotingServices:CreateClientProxy(Type, String, Object[])
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:LogError(Object)
HutongGames.PlayMaker.ActionData:CreateAction(FsmState, Int32)
HutongGames.PlayMaker.ActionData:LoadActions(FsmState)
HutongGames.PlayMaker.FsmState:LoadActions()
HutongGames.PlayMaker.Fsm:InitData()
HutongGames.PlayMaker.Fsm:Init(MonoBehaviour)
PlayMakerFSM:Init()
PlayMakerFSM:Awake()

System.InvalidCastException: Unable to cast object of type 'TestEnum' to type 'Int32'.
  at System.Array.SetValueImpl (System.Object value, Int32 pos) [0x00000] in <filename unknown>:0
  at System.Array.SetValue (System.Object value, Int32 index) [0x00000] in <filename unknown>:0
  at HutongGames.PlayMaker.ActionData.LoadArrayElement (System.Array field, System.Type fieldType, Int32 elementIndex, Int32 paramIndex) [0x00000] in <filename unknown>:0
  at HutongGames.PlayMaker.ActionData.LoadActionField (System.Object obj, System.Reflection.FieldInfo field, Int32 paramIndex) [0x00000] in <filename unknown>:0
  at HutongGames.PlayMaker.ActionData.CreateAction (HutongGames.PlayMaker.FsmState state, Int32 actionIndex) [0x00000] in <filename unknown>:0
  at HutongGames.PlayMaker.ActionData.LoadActions (HutongGames.PlayMaker.FsmState state) [0x00000] in <filename unknown>:0
  at HutongGames.PlayMaker.FsmState.LoadActions () [0x00000] in <filename unknown>:0
  at HutongGames.PlayMaker.Fsm.InitData () [0x00000] in <filename unknown>:0
  at HutongGames.PlayMaker.Fsm.Init (UnityEngine.MonoBehaviour component) [0x00000] in <filename unknown>:0
  at PlayMakerFSM.Init () [0x00000] in <filename unknown>:0
  at PlayMakerFSM.Awake () [0x00000] in <filename unknown>:0
  at Replacements.RemotingServices.CreateClientProxy (System.Type objectType, System.String url, System.Object[] activationAttributes) [0x00000] in <filename unknown>:0
Replacements.RemotingServices:CreateClientProxy(Type, String, Object[])
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:LogError(Object)
HutongGames.PlayMaker.ActionData:CreateAction(FsmState, Int32)
HutongGames.PlayMaker.ActionData:LoadActions(FsmState)
HutongGames.PlayMaker.FsmState:LoadActions()
HutongGames.PlayMaker.Fsm:InitData()
HutongGames.PlayMaker.Fsm:Init(MonoBehaviour)
PlayMakerFSM:Init()
PlayMakerFSM:Awake()
Replacements.RemotingServices:CreateClientProxy(Type, String, Object[])

Thoughts?  This goes away if I disable IL2CPP.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: IL2CPP problem with enum arrays
« Reply #1 on: April 17, 2015, 03:01:35 AM »
Hi,

 is it Unity 4 or 5? Can you double check with the latest versions ( 4.6.4 is out, and there is also a patch for 5 that just came out)

 If you still have this issue, let me know.

Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: IL2CPP problem with enum arrays
« Reply #2 on: April 20, 2015, 09:30:12 AM »
Hi,

 facing the same issue here, but a on a really big project, so we can't find out yet what is the code or else that is causing this on our end. Apparently Enumarable have changed the way they work...

Bye,

 Jean

MaddestOfHatters

  • Playmaker Newbie
  • *
  • Posts: 8
Re: IL2CPP problem with enum arrays
« Reply #3 on: May 05, 2015, 04:49:01 PM »
In a more recent version of Unity (4.6.4p4) what was originally a crash has now become incorrect behavior.  Rather than crashing in the PlayMaker initialization we simply don't see any values stored in the enum array.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: IL2CPP problem with enum arrays
« Reply #4 on: May 06, 2015, 10:04:00 AM »
Hi,

 I am confused, PlayMaker doesn't deal with enums yet, so if you write a custom action using enums, it's only to actually be used by the action code. Can you explain a bit more about the context?

also, how do you witness that values are incorrect?

 Bye,

 Jean

MaddestOfHatters

  • Playmaker Newbie
  • *
  • Posts: 8
Re: IL2CPP problem with enum arrays
« Reply #5 on: May 06, 2015, 07:56:23 PM »
We have a custom action that can handle a number of different cases.  Those cases are described by an enum.  When editing the FSM we add enums to the array.  These are used by the custom action only, in order to determine its behavior.

Previously we saw a crash on iOS caused by the unhandled exception described above.  The crash is gone in 4.6.4p4 but now we are not seeing any values in these arrays (at run-time they are empty).

This is code that we've used for some time without problem and it still works correctly if we compile to Mono and forgo IL2CPP.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: IL2CPP problem with enum arrays
« Reply #6 on: May 07, 2015, 05:21:29 AM »
Hi,

 I'll still need a lot more details to understand the concept :)

 How do you use "array" in the PlayMaker context? There is no such things built in PlayMaker. So this is an important aspect to explain so that I can see what could be wrong.

How do you see that the values are empty at runtime? do you use code or do you use a debugger of some sort ( logs, analytics, unity debugger, unity profiler?)

Is it possible the get the whole Action code ( pm me if it's private), and I'll try to reproduce locally.

 Bye,

 Jean

MaddestOfHatters

  • Playmaker Newbie
  • *
  • Posts: 8
Re: IL2CPP problem with enum arrays
« Reply #7 on: May 07, 2015, 09:41:51 PM »
Code: [Select]
enum MyEnum { A, B, C }
class EnumBasedAction : FsmStateAction
{
  public MyEnum[] enumValues;

  public override void OnEnter()
  {
    if (enumValues == null || enumValues.Length <= 0)
    {
      Debug.Log("No enums found!"); // this gets called, even if enum values were present, and only on IL2CPP
      return;
    }

    // how we actually use the enums
    foreach (MyEnum enumVal in enumVals)
    {
      if (enumVal == MyEnum.A) { DoA(); }
      ...
    }
  }

}
« Last Edit: May 07, 2015, 09:47:58 PM by MaddestOfHatters »

MaddestOfHatters

  • Playmaker Newbie
  • *
  • Posts: 8
Re: IL2CPP problem with enum arrays
« Reply #8 on: May 07, 2015, 10:03:23 PM »
Hrm.  FWIW, I can't repro this in a simple test project.  I'm not sure what the difference is between that and our full project.  It could be related to loading from asset bundles or it could be some other conflict within IL2CPP that only happens with the rest of our code there.  I was able to repro the original crash in an older version of Unity.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: IL2CPP problem with enum arrays
« Reply #9 on: May 08, 2015, 01:45:10 AM »
Hi,

 Oh, these bugs are annoying isn't it :)

 You should report this to Unity, we have another Playmaker member that had similar problem ( with nested prefab loosing references to other objects in subsub levels) when loading from resources, while totally fine otherwise with the same prefab. So It's likely some quirks with alternative serialization ( coming from resources or bundles).

 Bye,

 Jean