Browse Source

Ignore calls to Session.requestAnimationFrame() if the session has been ended

customisations
alemart 11 months ago
parent
commit
59d8524414
2 changed files with 16 additions and 6 deletions
  1. 10
    3
      docs/api/session.md
  2. 6
    3
      src/core/session.ts

+ 10
- 3
docs/api/session.md View File

66
 
66
 
67
 Schedules a call to the `callback` function, which is intended to update and render the virtual scene. Your `callback` function must itself call `session.requestAnimationFrame()` again in order to continue to update and render the virtual scene.
67
 Schedules a call to the `callback` function, which is intended to update and render the virtual scene. Your `callback` function must itself call `session.requestAnimationFrame()` again in order to continue to update and render the virtual scene.
68
 
68
 
69
-!!! info "Note"
69
+!!! info "Notes"
70
 
70
 
71
     `session.requestAnimationFrame()` is analogous to `window.requestAnimationFrame()`, but they are not the same! The former is a call to the WebAR engine, whereas the latter is a standard call to the web browser.
71
     `session.requestAnimationFrame()` is analogous to `window.requestAnimationFrame()`, but they are not the same! The former is a call to the WebAR engine, whereas the latter is a standard call to the web browser.
72
 
72
 
73
+    This call will be ignored and an invalid handle will be returned if the session has been [ended](#ended) (*since 0.3.0*). Previously, it would raise an exception.
74
+
73
 **Arguments**
75
 **Arguments**
74
 
76
 
75
 * `callback: function`. A function that receives two parameters:
77
 * `callback: function`. A function that receives two parameters:
83
 **Example**
85
 **Example**
84
 
86
 
85
 ```js
87
 ```js
88
+//
89
+// This is the animation loop:
90
+//
91
+
86
 function animate(time, frame)
92
 function animate(time, frame)
87
 {
93
 {
88
     // update and render the virtual scene
94
     // update and render the virtual scene
89
     // ...
95
     // ...
90
 
96
 
91
-    // repeat the call
97
+    // repeat
92
     session.requestAnimationFrame(animate);
98
     session.requestAnimationFrame(animate);
93
 }
99
 }
94
 
100
 
101
+// start the animation loop
95
 session.requestAnimationFrame(animate);
102
 session.requestAnimationFrame(animate);
96
 ```
103
 ```
97
 
104
 
103
 
110
 
104
 **Arguments**
111
 **Arguments**
105
 
112
 
106
-* `handle: SessionRequestAnimationFrameHandle`. A handle returned by `session.requestAnimationFrame()`.
113
+* `handle: SessionRequestAnimationFrameHandle`. A handle returned by `session.requestAnimationFrame()`. If the handle is invalid, this method does nothing.
107
 
114
 
108
 ### end
115
 ### end
109
 
116
 

+ 6
- 3
src/core/session.ts View File

418
     {
418
     {
419
         const handle: SessionRequestAnimationFrameHandle = Symbol('raf-handle');
419
         const handle: SessionRequestAnimationFrameHandle = Symbol('raf-handle');
420
 
420
 
421
-        if(this._active)
421
+        if(this._active) {
422
             this._rafQueue.push([ handle, callback ]);
422
             this._rafQueue.push([ handle, callback ]);
423
-        else
424
-            throw new IllegalOperationError(`Can't requestAnimationFrame(): session ended.`);
423
+        }
424
+        else {
425
+            // if the session is inactive, we simply ignore this call
426
+            // this is friendly behavior, since RAF is used in animation loops
427
+        }
425
 
428
 
426
         return handle;
429
         return handle;
427
     }
430
     }

Loading…
Cancel
Save