this.output is undefined after calling .remove() on an instance.

Thanks in advance!

I'm running the following snippet:

    var sketch;


    if (typeof(sketch) == 'undefined' ){                       
                sketch = new p5(fft, "sketchDiv");
            } else {
                sketch = new p5(fft, "sketchDiv");

When I click the title div once, it works...

When I click it a second time, it also works (removes and replaces).

However, when I click it a third time, the console reports the error:

" this.output is undefined"

  • If I click it a fourth time everything runs again as planned *

Not sure why the error isn't getting called after the first "remove()" call.

Here is the sketch: (in instance mode).

      var fft = function (p){

       p.mic, p.fft;

        p.setup = function() {

 p.mic = new p5.AudioIn();
 p.fft = new p5.FFT();

     p.draw = function() {

      p.clear();  // using this instead of redrawing background

       var spectrum = p.fft.analyze();


 for (i = 0; i<spectrum.length; i++) {
  p.vertex(i,[i], 0, 250, p.height, 0) );

} }


  • First suggestion. Add this in your line 4: console.log("step0: "+typeof(sketch)); I am curious to see what line of the code causes the error, is it within the if caluse or the else?

    Could you provide more details about why you want to do this? Couldn't you just modified the current state of your sketch, or re-init your sketch instead of creating a new object?


  • It logs as "step0 = object".

  • edited May 2017

    re-init sounds interesting... how do you mean? I am basically trying to avoid having sketches stacked on sketches in my div.

  • I am basically trying to avoid having sketches stacked on sketches in my div.

    What do you mean? Could you provide your html file? Do you define two div objects in your body?


Sign In or Register to comment.