comparison Applications/Platforms/WebAssembly/WebAssemblyViewport.h @ 1623:74be0f498b08

Updated mechanism to avoid using deleted objects in RequestAnimationFrame callbacks.
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 04 Nov 2020 11:39:15 +0100
parents 575f512cdf48
children 9ac2a65d4172
comparison
equal deleted inserted replaced
1622:0f8d6791b403 1623:74be0f498b08
59 std::unique_ptr<ViewportController> controller_; 59 std::unique_ptr<ViewportController> controller_;
60 std::unique_ptr<IViewportInteractor> interactor_; 60 std::unique_ptr<IViewportInteractor> interactor_;
61 bool enableEmscriptenMouseEvents_; 61 bool enableEmscriptenMouseEvents_;
62 unsigned int canvasWidth_; 62 unsigned int canvasWidth_;
63 unsigned int canvasHeight_; 63 unsigned int canvasHeight_;
64 std::vector<long> animationFrameCallbackIds_;
65 void* objectCookie_;
66 64
67 static EM_BOOL OnRequestAnimationFrame(double time, void *userData); 65 static EM_BOOL OnRequestAnimationFrame(double time, void *userData);
68 66
69 static EM_BOOL OnResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData); 67 static EM_BOOL OnResize(int eventType, const EmscriptenUiEvent *uiEvent, void *userData);
70 68
107 * C-style callbacks that expect the object to be passed as a void* 105 * C-style callbacks that expect the object to be passed as a void*
108 * 106 *
109 * This cookie is a resource and must be freed when it is guaranteed 107 * This cookie is a resource and must be freed when it is guaranteed
110 * not to be used anymore, with ReleaseObjectCookie 108 * not to be used anymore, with ReleaseObjectCookie
111 */ 109 */
112 void* GetObjectCookie(); 110 void* CreateObjectCookie();
113 111
114 /** 112 /**
115 * This static method can be used to dereference a cookie (i.e. retrieve 113 * This static method can be used to dereference a cookie (i.e. retrieve
116 * a pointer to the underlying object) that has been created with 114 * a pointer to the underlying object) that has been created with
117 * WebAssemblyViewport::GetObjectCookie() 115 * WebAssemblyViewport::CreateObjectCookie()
118 * 116 *
119 * If this method returns NULL, it basically means that the 117 * If this method returns NULL, it basically means that the
120 * WebAssemblyViewport has already been deleted and that you should NOT 118 * WebAssemblyViewport has already been deleted and that you should NOT
121 * attempt to use it! 119 * attempt to use it!
122 * 120 *
126 * If this method is called AFTER ReleaseObjectCookie has been called on 124 * If this method is called AFTER ReleaseObjectCookie has been called on
127 * the same cookie, the behavior is undefined and things will CERTAINLY 125 * the same cookie, the behavior is undefined and things will CERTAINLY
128 * go wrong. 126 * go wrong.
129 * 127 *
130 * NEVER call this method on a void* that has not been generated by the 128 * NEVER call this method on a void* that has not been generated by the
131 * GetObjectCookie method of this class 129 * CreateObjectCookie method of this class
132 */ 130 */
133 static WebAssemblyViewport* DereferenceObjectCookie(void* cookie); 131 static WebAssemblyViewport* DereferenceObjectCookie(void* cookie);
134 132
135 /** 133 /**
136 * This method must be used when the object cookie will not be used anymore. 134 * This method must be used when the object cookie will not be used anymore.