Skip to content
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

Calling .remove(func) on a C# static event after a .add(func) makes further .add()'s fail to be called #112

Closed
TheMightyGit opened this issue Sep 21, 2015 · 6 comments

Comments

@TheMightyGit
Copy link

These steps happen in my code (using 0.9.8)...

  • I have a C# static event, and in Lua code I myEvent.add(lua_func) to it. Event triggers lua code just fine. Hooray!
  • I use myEvent.remove(lua_func) to remove it from the event. Event no longer triggers lua code, as expected.
  • I use myEvent.add(another_lua_func) on event. But this code is not called when the event triggers :(

If I put in a dummy delegate before the above - it all works as expected.

So I think that when I remove the last delegate from the event it somehow resets its state, and for some reason from then on Moonsharp is no longer looking at the same event? As if returning the event it to null actually created a new event object (I'm no C# expert, but it seems that events/delegate do some magic in their null state).

Does this sound plausible?

NOTE: I have previously noticed that I need to Unregister and Register classes with static events in them if I null any of the static events, otherwise they no longer work - this seems like its the same(?) issue.

@TheMightyGit TheMightyGit changed the title Calling .remove(func) on a C# event after a .add(func) makes further .add()'s fail to be called Calling .remove(func) on a C# static event after a .add(func) makes further .add()'s fail to be called Sep 21, 2015
@TheMightyGit
Copy link
Author

Using net35 in Unity (4.6.8f1), I should add.

@xanathar
Copy link
Member

Event management in MoonSharp is enormously complex, so a bug there is not unlikely !

Will check this asap. (Ideally I want to go 1.0 pretty soon, so I'll try to fix sooner than later!)

@TheMightyGit
Copy link
Author

Cool :) For now I can use my work around. Good luck bug hunting. Let me know if you have any trouble reproducing it, if you do then I can try and make a minimal Unity project that exhibits the problem.

xanathar added a commit that referenced this issue Sep 23, 2015
@xanathar
Copy link
Member

Solved on master (not yet deployed on binaries!)

@TheMightyGit
Copy link
Author

Confirmed working using latest src in Unity project. \o/ Thank you :D

@xanathar
Copy link
Member

xanathar commented Oct 9, 2015

You're welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants