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

Extracted fields for delegates in BindCallbacks #7

Merged
merged 2 commits into from
Apr 29, 2019

Conversation

theraot
Copy link
Contributor

@theraot theraot commented Apr 29, 2019

Since the GC is not aware that the extern calls hold reference to passed delegates, it will collect these delegates which will result in some nasty exceptions※. To prevent this, I have extracted the delegates as fields, which will be tied to the lifetime of the NativeWindow object (making sure the GC does not collect them before collecting the NativeWindow object).

※: I was getting ExecutionEngineException on .NET Core and CallbackOnCollectedDelegate on .NET Framework on calls to Glfw.PollEvents.

I have tested that my code works with builds of glfw-net that include this change and the problem has not come back.

Note: I had missed SetErrorCallback the first time around.

@theraot theraot changed the title Extracted fields for delegates in BindCallbacks Extracted fields for delegates in BindCallbacks [WIP] Apr 29, 2019
@theraot theraot changed the title Extracted fields for delegates in BindCallbacks [WIP] Extracted fields for delegates in BindCallbacks Apr 29, 2019
@ForeverZer0
Copy link
Owner

ForeverZer0 commented Apr 29, 2019

Good catch, my primary testing ground has been .NET Core on Arch Linux, I apparently missed that test with the .NET Framework.

I will likely create a new release later today with the merged changes.

@ForeverZer0 ForeverZer0 merged commit 0bf610f into ForeverZer0:master Apr 29, 2019
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

Successfully merging this pull request may close these issues.

2 participants