p5.js-sound icon indicating copy to clipboard operation
p5.js-sound copied to clipboard

.play() throws error - Cannot read property 'length' of undefined - RingBuffer.push()

Open BrewHog opened this issue 3 years ago • 26 comments

/** [p5.sound] Version: 0.3.12 - 2020-01-06 */

A new problem arose yesterday or the day before. I've been using the same code for a couple of weeks with no problems.

If you call .play() after .loadSound(), the following error/stack is thrown:

730ccbef-3078-419b-80e3-0b3b03baca05:75 Uncaught TypeError: Cannot read property 'length' of undefined at RingBuffer.push (730ccbef-3078-419b-80e3-0b3b03baca05:75) at AudioWorkletProcessor.process (730ccbef-3078-419b-80e3-0b3b03baca05:170) push @ 730ccbef-3078-419b-80e3-0b3b03baca05:75 process @ 730ccbef-3078-419b-80e3-0b3b03baca05:170

This can be observed on the official p5js.org website here: https://p5js.org/reference/#/p5.EQ Click on the 'lows' button to throw the error

I've tested this on multiple browsers with the same error. Currently I'm testing on Chrome (Version 84.0.4147.105 (Official Build) (64-bit)).

I've never submitted before, so I don't know if I'm reporting this properly, or if this is already known/tracked.

BrewHog avatar Aug 04 '20 18:08 BrewHog

I've been able to use the developer portable version of Firefox (v80) to get around this issue. The error is still thrown, but the methods work properly on that version.

BrewHog avatar Aug 04 '20 18:08 BrewHog

I am having exactly the same problem - this is on code which was working perfectly before, but now suddenly throws an error as soon as I attempt to play any sound file.

I have written a simple test case which will cause the error to display:

const audioFile = '[insert path to audio file here]';
let audioStream;
let playing = false;

window.setup = () => {
  createCanvas(640, 480);
  background(0,128,0)
  audioStream = loadSound(audioFile, function () {
    console.log('loaded', audioFile);
  });
  console.log('loading', audioFile);
};

window.draw = () => {
  if (!playing && audioStream.isLoaded()) {
    playing = true;
    console.log('play');
    audioStream.play();
    console.log('playing');
  }
};

dansumption avatar Aug 12 '20 13:08 dansumption

This PR fixes the RingBuffer length error and the currentTime() issue https://github.com/processing/p5.js-sound/pull/542

MrRoboman avatar Aug 24 '20 04:08 MrRoboman

how do you get this fix for the ringbuffer.length()? also having this appear in my projects.

atagger avatar Sep 14 '20 20:09 atagger

how do you get this fix for the ringbuffer.length()? also having this appear in my projects.

I guess with the next release of the p5 sound library.

joepdooper avatar Sep 20 '20 15:09 joepdooper

I rolled back to 0.3.0 p5 sound until they fix it.

atagger avatar Sep 21 '20 16:09 atagger

I have this issue when running version 1.1.9. Anyone else?

Tsourdox avatar Jan 08 '21 09:01 Tsourdox

Yes, I am still having this error. Here are some reasons...

Firstly, last time I looked, the fix for this didn't yet appear to have been merged into the latest release (which came out about 6 months ago). I've not checked again for the last few weeks, but obviously without the fix in the release, the release won't be fixed!

However I went into the code and manually applied the fix to my own version. It meant that the error messages stopped, but my app still did not work. On checking the code, all that it does is short-circuit the error messages. It does not address whatever it is that is causing the error in the first place.

dansumption avatar Jan 08 '21 09:01 dansumption

I'm still having this issue, as well as cracking sounds in version 1.3.1 as well! Hope for a fix soon!

I dont know why this issue is closed because it is not fixed.

casperleerink avatar Apr 01 '21 19:04 casperleerink

I got this error too, any news?

AoiYamada avatar Apr 05 '21 11:04 AoiYamada

This issue should not be closed, as the issue still occurs.

paraclete-pizza avatar Apr 26 '21 15:04 paraclete-pizza

Agreed, this is very much a live issue. Sadly I had to abandon my p5js project because of this issue.

dansumption avatar Apr 26 '21 15:04 dansumption

Same here, basically stuck using old versions of p5 sound.

atagger avatar Apr 26 '21 16:04 atagger

Also still having this error. NFTs on hicetnunc won't run on iPhone safari because of this.

theantonius avatar Apr 29 '21 03:04 theantonius

Confirming, having the same issue, happening when simply using .loop() or .jump()

EXPSTUDIOmo avatar May 09 '21 17:05 EXPSTUDIOmo

I have the same problem

Same here, basically stuck using old versions of p5 sound. What version are you using?

piaaaac avatar May 20 '21 06:05 piaaaac

I switched to Howler.js for soundfile playback. Can recommend! Great API, great performance.

EXPSTUDIOmo avatar May 20 '21 06:05 EXPSTUDIOmo

Damn, that gave me hope of finally fixing my scripts... sadly seems that Howler.js is only for playing sounds, doesn't have methods for fetching eq & spectrum data.

Does anyone know if there are actually any maintainers for p5.sound? This issue has been present for 9 months now, and no input from anyone about getting it fixed or even re-opened.

dansumption avatar May 20 '21 09:05 dansumption

There is another thread here with some info (potentially?): https://github.com/processing/p5.js-sound/issues/494

atagger avatar May 20 '21 13:05 atagger

Looks like the issue was resolved there with updating chrome - but this can't be resolved with chrome updates.

theantonius avatar May 22 '21 22:05 theantonius

@theantonius I'm still seeing this issue in the latest dev build of Chrome.

@therewasaguy Please re-open, this is still an issue according to multiple reports above.

bendavis78 avatar May 25 '21 20:05 bendavis78

We need to properly release a new version of the library that includes the fix. I think this is how to do it, and I'll try to do that right now!

I'm very sorry that it's taken so long to release a new version. I've been a terrible maintainer and I feel terrible about that. I would be happy to make space for others, please reach out if you're interested.

therewasaguy avatar May 26 '21 02:05 therewasaguy

I'll leave this open with https://github.com/processing/p5.js/pull/5266

therewasaguy avatar May 26 '21 03:05 therewasaguy

@therewasaguy I'm not sure that merging the "fix" will fix things - see my comment here: https://github.com/processing/p5.js-sound/issues/506#issuecomment-756658958

I wrote a test case which highlights the error: https://github.com/processing/p5.js-sound/issues/506#issuecomment-672873135

dansumption avatar May 26 '21 08:05 dansumption

thanks for the test case, @dansumption !

I took a quick look. If the test case was working before and now it isn't, that sounds like a regression / bug! But this might be a different / smaller issue because the test case assigns the result of loadSound to a variable in setup() and that approach isn't meant to work outside of preload().

It seems to work if we instead assign within preload like this

window.preload = () => {
  audioStream = loadSound(audioFile, function () {
    console.log('loaded', audioFile);
  });
};

or from the callback like this

window.setup = () => {
  createCanvas(640, 480);
  background(0,128,0)
  loadSound(audioFile, function (gotFile) {
    audioStream = gotFile;
    console.log('loaded', audioFile);
  });
  console.log('loading', audioFile);
};

The documentation isn't clear on this, I see how it's confusing! We should create a second example, similar to the "outside of preload" example for loadJSON on this page - would anyone like to take that on?

therewasaguy avatar May 27 '21 18:05 therewasaguy

Ah, thanks for that @therewasaguy !

This seems to work, although the code I left in a very messy state about a year ago still isn't working (my problem being that I'm not getting regular samples back from the audio once playing). This may well be something I've messed up - really need to re-familiarise myself with the project - but I do seem to recall getting it to a similar working state before, and still not able to get samples from the sound object.

I will see what more I can figure out, when I have a moment. Hopefully all fixed, but... possibly not.

dansumption avatar May 28 '21 13:05 dansumption