-
Notifications
You must be signed in to change notification settings - Fork 23
A big chunk of this crate seems unsound to me #18
Comments
There is some doc about how raw pointers are used here: https://github.com/servo/servo/blob/master/components/webvr/webvr_thread.rs#L294 Besides Servo WebVR implementation, one of the use cases intended for this library was to allow using it by any standalone rust app. |
My issue is that |
I get the point. Maybe is not well documented but the assumption is that nobody is going to sync poses or submit frames to a VRDevice from different threads at the same time (== calling mutable methods). That would fail on the underlying native SDKs even using If there is a better container to express all that at compile time that would be great. The use case is a shared pointer reference that can send between threads, inmutable methods can be called safely from any thread, but mutable methods are only called from the same render thread at a time (it could be sent to another render thread for a different VR sessionm but only one at a time). |
When you say "that would fail", how would the failure manifest itself? |
Undefined crashes per platform, I mean that the native SDKs are not expected to be called from different threads at the same time for submitting frames or syncing the pose. |
Ok, then that should definitely never be doable from safe code. :) Not like we are going to resolve this issue today though. I think we should wait and discuss about that IRL when our overlord Lars has a date for the workweek. :3 |
Just stumbled across this: We should at least swap the
This isn't safe; you shouldn't be able to read from the other threads whilst the render thread is mutating. I think this should just be |
+1 for |
And now it's my turn. If the idea is to have a read-only view of the display that can be used from any thread, and a read-write view that can only be used from the thread that created it, then are we wanting two types? |
AFAICT the implementations allow UB from safe code, due to (e.g.)
To get UB:
I don't think this will be fixed by moving to |
A conversation with @MortimerGoro on slack today (so no permalink because it's not public). The argument for soundness seems to be that there's two threads with access to the same I'm not sure about this, e.g. https://github.com/servo/servo/blob/81ab255b70cd5cc2a3ef6f27414c3655ed26a82f/components/script/dom/vrdisplay.rs#L201 sends a |
Oh, and I should add that this is coming up for me because I'm implementing the magicleap back end, for which the |
GetFrameData only goes thought the WebVR thread when it's not presenting (also called magic window mode). In that situation SubmitFrame cannot be called from JS. When it's presenting the FrameData it's received from the GL thread that generated it.
Could you create the GLContext only when WebXR presentation starts or do you need it earlier? As mentioned in slack once we have support for all the external textures in Servo WebGL (e.g. SurfaceTextures on Android, IOSurfaces on mac, etc) we won't need to call the SubmitFrame() and other render methods from the same WebGL thread. That could simplify a lot of things and maybe we can move all the code to a single thread in webvr_thread.rs |
Hmm, so the safety relies on the fact that the display is still presenting when I could create the GL context when the presentation starts, but it would be much nicer if I could make the |
Many APIs in there use a
Arc<RefCell<T>>
, and then use that as raw pointers somehow on the Servo side. That seems highly suspicious to me. @MortimerGoro Is there some documentation somewhere about how this is all used?The text was updated successfully, but these errors were encountered: