TooTallNate / node-speaker

Output PCM audio data to the speakers
654 stars 147 forks source link

Error occurs occasionally in Mac OSX. "libc++abi.dylib: Pure virtual function called !" #62

Open teegh opened 9 years ago

teegh commented 9 years ago

Hi, I am very grateful to node-speaker. I have some questions. When repeatedly play music, error occurs occasionally in Mac OSX. (It does not occur in linux.) The error occurs in the following. Is this a problem of xcode? Or will the problem of node-speaker? Please give me some advice.

https://github.com/teegh/speakerErrorCase

./node_modules/speaker/index.js 353

binding.close(this.audio_handle);

Error occurs in the above codes. Error message was following.

libc++abi.dylib: Pure virtual function called!

Speaker.prototype.close = function (flush) {
  debug('close(%o)', flush);
  if (this._closed) return debug('already closed...');

  if (this.audio_handle) {
    if (false !== flush) {
      // TODO: async most likely…
      debug('invoking flush() native binding');
      binding.flush(this.audio_handle);
    }

    // TODO: async maybe?
    debug('invoking close() native binding');

    console.log("binding.close start");
    binding.close(this.audio_handle);  //Error occurs occasionally in Mac OSX. "libc++abi.dylib: Pure virtual function called !"
    console.log("binding.close complete");

    this.audio_handle = null;
  } else {
    debug('not invoking flush() or close() bindings since no `audio_handle`');
  }

  this._closed = true;
  this.emit('close');
};
kicumkicum commented 9 years ago

+1

ChrisMcKenzie commented 9 years ago

:+1:

ibc commented 9 years ago

+1 +1 +1

llaine commented 8 years ago

+1

pschroen commented 8 years ago

+1

jarodreyes commented 8 years ago

+1

brian-thornton commented 8 years ago

+1 I am hitting this on Mac El Capitan 10.11.1

tbass134 commented 7 years ago

+1

wiill commented 7 years ago

+1

jmp1548 commented 7 years ago

+1 😢

teegh commented 6 years ago

I tackling this problem after a while. In order to avoid the error, it turned out that you had better stop music playing yourself.

For example, The follow is a simple code. Perhaps I think it is important to call decoder.unpipe() and bufferStream.end() themselves.

const lame    = require('lame')
const Speaker = require('speaker')
const stream  = require("stream")
let sound_duration = 3*60*1000  // e.g.  3 minutes song

setTimeout( () => { 
            bufferStream = new stream.PassThrough()
            decoder = new lame.Decoder()
            speaker  = new Speaker()

            bufferStream.end( SOUND_DATA_BUFFER )
            bufferStream.pipe( decoder )
                .on("error", () => { /*doSomething*/ })
                .on("close", () => { /*doSomething*/ })
                .on("unpipe", () => { /*doSomething*/ })
                .on("end", () => { /*doSomething*/ })
                .pipe(speaker)
                .on("finish", () => { /*doSomething*/ })
}, 500)

// Forcibly stop music right before the end of performance
setTimeout( () => {
            setTimeout( () => { console.log("bufferStream pause"); bufferStream.pause()}, 500)
            setTimeout( () => { console.log("bufferStream unpipe"); bufferStream.unpipe()}, 1000)
            setTimeout( () => { console.log("decoder unpipe"); decoder.unpipe()}, 1500)
            setTimeout( () => { console.log("bufferStream end"); bufferStream.end()}, 2000)
            setTimeout( () => { console.log("speaker end"); speaker.close()}, 2500)
            setTimeout( () => { console.log("--- play next ---"); }, 3000)
} , sound_duration - 2500)