Closed jacksoncougar closed 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.
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?