Author Topic: v3.0.3e - EventDelegate.cs errors with windows phone  (Read 8596 times)

josha

  • Guest
v3.0.3e - EventDelegate.cs errors with windows phone
« on: October 29, 2013, 11:45:54 AM »
Hi,

I've just updated to 3.0.3e; I'm getting errors in EventDelegate.cs when selecting windows phone as build target.

I've added using System; at the top and swapped the code around with the #if / #else / #endif around line 71. But not sure if the latter is correct.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #1 on: October 29, 2013, 04:17:49 PM »
You need to be more precise here. Which lines, and what errors are you seeing? I don't have Windows 8, so I can't build for that platform.

josha

  • Guest
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #2 on: October 30, 2013, 01:32:38 AM »
Ah sorry, didn't realize you don't have win8.

There are two problems in EventDelegate.cs coming from the following code:

#if UNITY_METRO || UNITY_WP8
  static string GetMethodName (Callback callback)
  {
    Delegate d = callback as Delegate;
    return d.GetMethodInfo().Name;
  }
 
  static bool IsValid (Callback callback)
  {
    Delegate d = callback as Delegate;
    return d != null && d.GetMethodInfo() != null;
  }
#else
  static string GetMethodName (Callback callback) { return callback.Method.Name; }
  static bool IsValid (Callback callback) { return callback != null && callback.Method != null; }
#endif

The first problem is that Unity can not find the Delegate class. Adding System to the import list will fix this, I've added:

#if UNITY_METRO || UNITY_WP8
using System;
#endif

However the second problem is that Unity then gives an error because it can not find the Delegates GetMethodInfo() method. This is a bug from Unity I guess, because the following post claims it should be supported in winphone 8:
http://msdn.microsoft.com/en-US/library/windowsphone/develop/system.reflection.runtimereflectionextensions.getmethodinfo%28v=vs.105%29.aspx

Because I'm in the editor I'm sure System.Reflection is imported, because of the code:

#if UNITY_EDITOR || (!UNITY_FLASH && !UNITY_WP8 && !UNITY_METRO)
#define REFLECTION_SUPPORT
#endif

#if REFLECTION_SUPPORT
using System.Reflection;
#endif

I've fixed the compiler error by changing to the following code (not sure how correct it is though):

#if UNITY_METRO || UNITY_WP8
  static string GetMethodName (Callback callback)
  {
    Delegate d = callback as Delegate;
    return d.Method.Name;
  }
 
  static bool IsValid (Callback callback)
  {
    Delegate d = callback as Delegate;
    return d != null && d.Method != null;
  }
#else
  static string GetMethodName (Callback callback) { return callback.Method.Name; }
  static bool IsValid (Callback callback) { return callback != null && callback.Method != null; }
#endif

Which I know is a bit silly since the metro/wp8 code basically does the same thing as the code at the #else part only with a typecast to Delegate.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #3 on: October 30, 2013, 03:07:46 AM »
Try replacing it with the following:
  1. #if !UNITY_EDITOR && (UNITY_METRO || UNITY_WP8)
  2.         static string GetMethodName (Callback callback)
  3.         {
  4.                 System.Delegate d = callback as System.Delegate;
  5.                 return d.GetMethodInfo().Name;
  6.         }
  7.  
  8.         static bool IsValid (Callback callback)
  9.         {
  10.                 System.Delegate d = callback as System.Delegate;
  11.                 return d != null && d.GetMethodInfo() != null;
  12.         }
  13. #else
  14.         static string GetMethodName (Callback callback) { return callback.Method.Name; }
  15.         static bool IsValid (Callback callback) { return callback != null && callback.Method != null; }
  16. #endif

josha

  • Guest
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #4 on: October 30, 2013, 05:45:33 AM »
Thanks for the quick reply. I just tried it. As expected within the Editor you no longer get the error (while Unity is parsing / compiling scripts). But once you do a build or build and run the compiling fails because of the same error (can not find GetMethodInfo() within Delegate).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #5 on: October 30, 2013, 06:16:58 AM »
This code was suggested by another user here (do a search for GetMethodInfo), so I'm at a loss then.

zazery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #6 on: October 30, 2013, 11:08:49 PM »
I believe you need to replace System.Delegate.GetMethodInfo() with System.Delegate.Method. It allowed me to compile my project to WP8. The project I'm working on crashes shortly after loading the first scene (which uses NGUI) due to tons of legacy plugins I need to update so I'm not absolutely certain this fixes it. If someone could confirm it works that would be great.

  1. #if !UNITY_EDITOR && (UNITY_METRO || UNITY_WP8)
  2.         static string GetMethodName (Callback callback)
  3.         {
  4.                 System.Delegate d = callback as System.Delegate;
  5.                 return d.Method.Name;
  6.         }
  7.  
  8.         static bool IsValid (Callback callback)
  9.         {
  10.                 System.Delegate d = callback as System.Delegate;
  11.                 return d != null && d.Method != null;
  12.         }
  13. #else
  14.    static string GetMethodName (Callback callback) { return callback.Method.Name; }
  15.         static bool IsValid (Callback callback) { return callback != null && callback.Method != null; }
  16. #endif

josha

  • Guest
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #7 on: October 31, 2013, 01:23:42 AM »
@zazery: your modification is the same as mine. Not sure if it works ok, but I've a project up and running on a WP8 (lumia 520) using the new EventDelegate to track ActiveAnimation OnFinish events. It does not crash and reacts correctly with the OnFinish events; although now I've to figure out why loaded textures (not related to the animations) are not showing (once I've some spare time) :(

zazery

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #8 on: October 31, 2013, 04:43:15 AM »
My mistake for not reading your post more carefully, yes it's the same change. The Method property should be identical to GetMethodInfo() from the documentation I've read. Since OnFinish worked properly in your project it's probably correct.

PixelEnvision

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 35
    • View Profile
    • Pixel Envision
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #9 on: October 31, 2013, 10:15:07 AM »
Just tried that with 3.0.3f, replaced GetMethodInfo() with Method in two places. Compile errors gone and things appears to be working fine. Is there an example scene that I can use to test this?
Pixel Envision - Creating fun apps for iOS & Android

Twitter / Facebook / YouTube

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: v3.0.3e - EventDelegate.cs errors with windows phone
« Reply #10 on: October 31, 2013, 06:52:21 PM »
Thanks, I'll patch it in then.