Skip to content

Commit ac43b2b

Browse files
committed
fix(QrcodeStream): stop worker on destroy
The worker which is processing scanning jobs, is not terminated when the component is destroyed. This was intended to be guaranteed by the following mechanism: 1. Component is destroyed (for example with `v-if="false"`) 2. `beforeDestroy` hook is called 3. `this.destroyed = true` 4. computed property `shouldStream` becomes `false` 5. computed property `shouldScan` becomes `false` 6. `shouldScan` watcher calls `stopScanning` Step 4 is never reached though. Probably becomes Vue won't re-evaluate computed properties after the `beforeDestroy` hook was called. So `stopScanning` is never called and the worker keeps processing frames. Results are still handed to the component which tries to paint to a canvas which doesn't exit anymore (since the component is destroyed). Hence causing errors like _Cannot read property 'getContext' of undefined_ See #85
1 parent dda944b commit ac43b2b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/components/QrcodeStream.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export default {
166166
167167
beforeDestroy () {
168168
this.beforeResetCamera()
169+
this.stopScanning()
169170
this.destroyed = true
170171
},
171172
@@ -189,14 +190,13 @@ export default {
189190
},
190191
191192
startScanning () {
192-
// this.stopScanning()
193-
194193
const detectHandler = result => {
195194
this.onDetect(
196195
Promise.resolve({ source: 'stream', ...result })
197196
)
198197
}
199198
199+
// this.stopScanning()
200200
this.stopScanning = keepScanning(this.cameraInstance, {
201201
detectHandler,
202202
locateHandler: this.onLocate,

0 commit comments

Comments
 (0)