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
To marshal a managed method, please add an attribute named 'MonoPInvokeCallback' to the method definition.-- at Plugins.Discord.DiscordRpc.Initialize #186
Comments
Hey there. I have not dug into (or heard of before this issue) compiling/using the SDK with IL2CPP in Unity, so I can't give you a quick answer. It looks like mono is complaining about things that may not be be a problem using the standard C# Unity stuff. Is IL2CPP a commonly used build mode with Unity? Are many other devs struggling with this as well? |
Thank you for your answer :). The standard Unity stuff is now to compile in c++ with il2cpp, it's a build option in Unity, that is mean to be the correct way of doing things. It is said to be faster. It's not a problem related to my project, but I couldnt find help on google about it. |
It seems like this may be related: https://garry.tv/2018/02/15/steamworks-and-il2cpp/ Perhaps try defining your own attribute like this? I can ask @snowyote to take a look when he has time. |
I tried with the same MonoPInvokeCallback on all discordrpc functions, but with no luck |
thank you |
Talked with him about this. Neither of us are really well versed in IL2CPP, so we can't say for sure what the fix would be right away. Considering you're the first to come across this issue, it seems like a somewhat non-standard way of doing things. I can put it on the docket to be addressed, but it's not a super high priority for us. If you figure out the changes and make a PR, we'll be happy to review. |
Changing the Callbacks to be static class members and doing the MonoPInvoke stuff works for me. |
Yes it works, thank you ! |
Thank you very much for your help @mdsitton! Marking this as closed. |
Windows il2cpp is now standard in Unity 2018.2+, going forward (and was already standard for iOS and... Android?): This is a stable version of Unity, meaning we must permanently resolve this issue, if you want Unity devs to continue using Discord RP: Please see the above referenced issue to try to port this to an il2cpp-friendly build for Unity ^ EDIT: Thread revival @ #243 |
I'm perfectly happy accepting a PR for the static class member changes if it won't break existing implementations (and it shouldn't?). Unless you have suggestions for a more "real" solution. As mentioned above, neither myself nor snowyote are well-versed in this il2cpp stuff, so we're going a bit on community knowledge here. |
Hey, I'm a dev at Unity working on IL2CPP, so I thought I might help here. The use of the The AOT code generator needs to know which managed methods could be called from native code, as it needs to generate marshaling wrappers. Doing this for all managed methods is not feasible, so the While IL2CPP is now an option for desktop standalone player builds in Unity 2018.2 and later, we plan to continue to support Mono JIT for those platforms. We don't plan to require IL2CPP as is the case on iOS, for example. Still, using |
[MonoPInvokeCallback(typeof(DiscordRpc.ErrorCallback))]
public static void ErrorCallback(int errorCode, string message)
{
Debug.Log(string.Format("Discord: error {0}: {1}", errorCode, message));
} @mdsitton Heya, while this 100% seems to be the right course of action, changing this causes a few domino effects on other things: What else did you change to get this working? I tried a few things but couldn't get it right. If you help us out @ #243 , there's $50 with your name on it. |
@dylanh724: Can to describe the other effects this causes in more detail? |
It should possibly be noted that Debug.Log() can only be called within the main thread. So, if you call ErrorCallback() from another thread, the Debug Output will not work. You have to follow the Synchronisation rules between threads in this case. |
I m having this issue with discord rpc under Unity 2018.1 , when using il2cpp as build mode, targeting windows.
I dont have this problem in the editor as it's mono.
I tried this:
public delegate void InitializeCallback(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId);
[MonoPInvokeCallback(typeof(InitializeCallback))]
[DllImport("discord-rpc", EntryPoint = "Discord_Initialize", CallingConvention = CallingConvention.Cdecl)]
public static extern void Initialize(string applicationId, ref EventHandlers handlers, bool autoRegister, string optionalSteamId);
but it doesnt help. Not sure if I'm doing the right thing
The text was updated successfully, but these errors were encountered: