artumino / PapyrusVR

Initial SKSE Plugin to expose OpenVR to Papyrus, feel free to make suggestions and open issues. BEWARE this is not a stable release, once PapyrusVR will be ready It will be published on the nexus.
GNU Lesser General Public License v3.0
11 stars 2 forks source link

Memory leak? #1

Closed jacksoncougar closed 6 years ago

jacksoncougar commented 6 years ago

https://github.com/artumino/PapyrusVR/blob/19c8c0d1eba9bb31cfe85ee7dfe0852b8a42abb2/PapyrusVR_Module/VRManager.cpp#L65

Init() creates new objects of both IVRCompositor and IVRSystem, but the check is only for if the compositor object is null.

Why is init called after a null check instead of initializing once during object creation?

artumino commented 6 years ago

vr::VRSystem() and vr::VRCompositor() don't instantiate new objects. They simply use two pointers (inside COpenVRContext wich is a singleton) to get the currently instantiated IVRCompositor and IVRSystem interfaces on OpenVR side. If they are not instantied it returns a null pointer without doing anything else.

As far as I know the only way to instantiate OpenVR interfaces is by calling VR_Init which procede to load vrclient library (where all the OpenVR interface logic resides). VR_Init is called by SkyrimVR just before the initial bethesda logo.

Still, We can avoid using this dirty trick and we can listen for a DataAvailable message from SKSE messaging interface and be certain that SkyrimVR has already instantiated all the OpenVR interfaces. I'll include the change in the next commit.