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

Alternate native preload #17

Merged
merged 3 commits into from
Jun 30, 2015
Merged

Alternate native preload #17

merged 3 commits into from
Jun 30, 2015

Conversation

rpavlik
Copy link
Member

@rpavlik rpavlik commented Jun 27, 2015

Turns out that the PATH manipulation in the Unity code doesn't work well (at all) with the SetDllDirectory static constructor I had added here. Thus, as suggested in OSVR/OSVR-Unity#19 (comment), I've switched to doing LoadLibrary calls of the DLLs in dependency order. Further, I've moved that out of a static constructor and just into a plain static method, for optional calling if you want that added help in ensuring you can find the native libs.

I can confirm that running the examples on a 64-bit machine (in 64-bit mode) works, and the assembly works when used with the Unity integration.

Caveats to my testing or design: I don't know if there's a way to only call the LoadLibrary code if it's required (in a static constructor, so it would be automatic in a more cautious way), or if Mono or other runtimes do a mapping so that a pinvoke of LoadLibrary makes something happen on non-Windows platforms thus making my inclusion of lib*.so code worthwhile. Also, at the moment we're just basically "leaking" the library handles - just a one-time thing, though, automatically cleaned up at process exit, (if the static method is called again, additional loadlibrary calls just increase a per-process ref count, so no way it will leak more than 4 library handles), and I wouldn't really expect to be able to change the native DLLs out from under an app while it's running anyway.

…etDllDirectory.

This means that when we believe we'll be able to find the libraries by
other means (like Unity setting the path), we can skip it.
They don't have a better way.
@rpavlik
Copy link
Member Author

rpavlik commented Jun 29, 2015

@JeroMiya Pushed changes to reflect your feedback and generally make the code more consumable

@rpavlik
Copy link
Member Author

rpavlik commented Jun 30, 2015

Per comment in the Unity issue, merging this as OK.

rpavlik added a commit that referenced this pull request Jun 30, 2015
@rpavlik rpavlik merged commit 60f5236 into master Jun 30, 2015
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.

None yet

1 participant