TooTallNate / node-speaker

Output PCM audio data to the speakers
648 stars 145 forks source link

crash on windows 10, node 10 #131

Closed checksummaster closed 4 years ago

checksummaster commented 5 years ago

At the event "close", my application exit. to fix that, i remove "delete ao->device;" (see below) but I'm not sure why .., maybe will leak but working.

NAN_METHOD(Close) { Nan::EscapableHandleScope scope; audio_output_t ao = UnwrapPointer<audio_output_t >(info[0]); ao->close(ao); int r = 0; if (ao->deinit) { r = ao->deinit(ao); } //delete ao->device; info.GetReturnValue().Set(scope.Escape(Nan::New(r))); }

JonSilver commented 4 years ago

@LinusU, @TooTallNate I'm still experiencing this behaviour even with the new v0.5.0. The app plays one stream, piped from lame, then exits with no error. Breakpointing on all or uncaught exceptions doesn't break. If the pipe from lame goes nowhere, bypassing speaker, the app remains running.

I've tried versions back to 0.3.1, where it worked, and have ascertained that this misbehaviour appeared between 0.4.0, with which it all worked fine, and 0.4.1 with which the app prematurely exits.

LinusU commented 4 years ago

I'm sorry to hear that, unfortunately I don't have access to a Windows 10 computer to try on πŸ€”

Would you be able to try commenting this line out:

https://github.com/TooTallNate/node-speaker/blob/8dc9e9cbc042e88a108c3381adac958f23cb4369/src/binding.c#L157

If that makes it work, we are probably double freeing that one. Just removing the free is probably the right thing to do, but it might be good to look at the source code for mpg123 to make sure that it's actually freeing it for us...

JonSilver commented 4 years ago

OK so I commented out the line, ran an npm rebuild speaker, and the test app worked. Is there a test that can ascertain whether it should be freed?

LinusU commented 4 years ago

Hmm, potentially this is not a double free, but rather that we are trying to free a static string 😁

https://github.com/TooTallNate/node-speaker/blob/20627e12f2628da8313544f5a92813f78cb3e68e/deps/mpg123/src/output/win32.c#L61

I need to dig deeper into this, potentially every backend works differently 😭

Hopefully I'll get some time this weekend! Thank you for testing πŸ‘

LinusU commented 4 years ago

Hmm, since the open call in the win32 output always overwrites the current device, I guess that it's leaking that memory already πŸ€·β€β™‚

Maybe the best thing for us to do is store the pointer to the device string out of band, and then free it after we've closed the ao instance πŸ€”

JonSilver commented 4 years ago

Sounds like a good plan. :)

LinusU commented 4 years ago

@JonSilver could you try out #139 and see if that solves the problem for you? ☺️

JonSilver commented 4 years ago

@LinusU Patch applied, rebuilt & tested... That seems to fix things nicely :)

LinusU commented 4 years ago

Awesome, I'll push a new release!

LinusU commented 4 years ago

Released in 🚒 0.5.1 / 2019-12-16

JonSilver commented 4 years ago

Cool... I'll await the npmjs.com release :)

LinusU commented 4 years ago

It's already live πŸ˜‰

Screenshot 2019-12-16 at 16 27 59