question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'x' of null

See original GitHub issue

I get this error from this line: https://github.com/ericblade/quagga2/blob/156938f0a83935744c375ad235c2d16dd06fb3f7/src/locator/barcode_locator.js#L58

It looks like _patchSize can be null. I would create a PR to fix this but I’m not sure what you want to happen in the case that _patchSize is null.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
UziTechcommented, Jul 21, 2020

I queued the call to init so if the button is pressed three times in quick succession the first press will call init the second press will be queued to be called after the first finishes and the third press will replace the second in the queue since the first one hadn’t finished yet and cancel the second init. Once the first init is done I run stop since there is another one queued and the third press will be executed.

Here is the code I used to do that:

	// this function called on button press to start the stream
	async startCapture() {
		if (this.capturing) {
			this.stopCapture();
		}

		this.codes = [];
		try {
			const success = await this.queueInit(this.mapState());
			if (!success) {
				// another call queued while this one was queued
				return;
			}
		} catch (ex) {
			// stop stream if `init` finished but there is another call queued
			Quagga.stop();
			if (ex) {
				throw ex;
			}
			return;
		}
		// `init` finished and not overridden by another call
		Quagga.start();
		this.capturing = true;
	}

	callInit(init) {
		let failed = false;
		this.currInit = Quagga.init(init.config)
			.catch((ex) => {
				// throw `ex` but still call `nextInit` if exists
				init.reject(ex);
				failed = true;
			})
			.then(() => {
				if (this.nextInit) {
					// start next call to `init`
					if (!failed) {
						init.reject();
					}
					const nextInit = this.nextInit;
					this.nextInit = null;
					this.callInit(nextInit);
				} else {
					// last call so continue `startCapture`
					this.currInit = null;
					if (!failed) {
						init.resolve(true);
					}
				}
			});
	}

	queueInit(config) {
		let init;
		const promise = new Promise((resolve, reject) => {
			init = {
				config,
				resolve,
				reject,
			};
		});
		if (this.currInit) {
			if (this.nextInit) {
				// cancel current queued call
				this.nextInit.resolve(false);
			}
			this.nextInit = init;
		} else {
			// no current calls
			this.callInit(init);
		}
		return promise;
	}
0reactions
ericbladecommented, Jul 21, 2020

Good find. I’m still not sure if that should throw an error or if it should just pass all 0’s to the remainder of the function. I’ve been spending most of my programming time on other projects but I’ll do some thinking / research on this one and see what i can find. i know there’s already an issue to investigate spamming start/stop potentially causing problems, which this seems like it would be related to.

can you share what your fix in your code involved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property of null - iDiallo
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns...
Read more >
Can't solve "Can't read property X of null" error - Stack Overflow
Basically the message says that null (as in, no object ref) does not have a property or method 'appendChild', which is obvious, because...
Read more >
TypeError: Cannot read property x of null - Codefresh
Symptoms When attempting to start a build, you receive the error TypeError: Cannot read property 'x' of null, where x is usually title,......
Read more >
Uncaught TypeError: Cannot read property 'x' of null #867
It seems to happen when you have a symbol that you scale to zero, and then have an onClick handler on another element....
Read more >
Uncaught TypeError: Cannot read property of undefined In
This error occurs in Chrome Browser when you read a property or call a method on an undefined object . There are a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found