Author Topic: SIGSEGV on mac when trying to capture microphone, or play sound over speakers  (Read 265 times)

scarboni

  • Posts: 32
Hello !

I have a software I have been developing lately. It works really great on windows, and today, I tried to make it work on macos.
The graphical interface, and most of things works greats, but, when I try to play music, or capture the microphone, I get a SIGSEGV and the app crashes.

The lib bass itself works fine, I can uses tags, I can see the timer of a non playing chan, but if I try to play music, even so chans are created and managed fine, it crashes.

I think mac os is blocking my software for some reason? Does anyone know about that?
Maybe I need some kind of authorization to use microphone or speaker ?

Edit: I didn't test before, but it crashes too when I try to stream (nothing but still)
« Last Edit: 27 Nov '20 - 13:55 by scarboni »

Ian @ un4seen

  • Administrator
  • Posts: 23311
You will need to include the NSMicrophoneUsageDescription option in your Info.plist file to request/enable recording on macOS, but the app shouldn't crash without that. To hopefully get some clues on the crash, please post the crash report (you can use the Utilities/Console app to access them). Also try to narrow it down to a line/call in your code where it's crashing, eg. by stepping through the code in a debugger or using logging.

scarboni

  • Posts: 32
I'm sorry, a Info.plist? What are you talking about?
I'm using the dylib files, I tried to use them in the same way that I use the dll fils until now, maybe I have missed something?

Also, if you are asking about when it's crashing in my code, it's exactly when I do

    this.micChan = this.objBass.BASS_RecordStart(
      44100,
      2,
      0,
      null
    );

for the mic manipulation. I didn't narrowed it down yet for the other crashes, but, I know it crashes only when I try to play on the speaker, or stream. (So it may include splitting or vumeter usage).

I will start by checking what you told me before looking for the other crashes.

Ian @ un4seen

  • Administrator
  • Posts: 23311
That BASS_RecordStart call seems to be missing the "user" parameter? That could cause a crash by unbalancing the stack.

Regarding Info.plist files, here's Apple's documentation on that:

   https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html

And here's the NSMicrophoneUsageDescription option:

   https://developer.apple.com/documentation/bundleresources/information_property_list/nsmicrophoneusagedescription

scarboni

  • Posts: 32
Thank you. I will look into that.

I'm using the dll/dylib from node, and, I've based my work over serkanp's work on that, in his examples, he was always getting rid of the user, since I didn't knew better, I followed in those steps. I had no problems so far with that on windows, but I don't really know what is user, or what it is used for?

What do you mean by "unbalancing the stack" ?

Ian @ un4seen

  • Administrator
  • Posts: 23311
"Unbalancing the stack" is when the stack pointer isn't the same before and after a function call. That could be caused by using the wrong calling convention or the wrong number/size of parameters. BASS expects the "stdcall" calling convention on Windows and "cdecl" on other platforms, so you need to make sure your wrapper is doing that. If the problem persists, also post the crash report.

scarboni

  • Posts: 32
I'm still looking into the issue and info.plist, but, while I do my research, here is the crash report I got :

scarboni

  • Posts: 32
Well, I did more tests, and you are definitely right ! It must be a stack imbalance. The segfault appear only wen i'm calling function supposed to use a user input. I can play sound just fine it seems.

The blockage comes up with functions like BASS_ChannelSetSync, or BASS_RecordStart which are supposed to use a user !

Do you have an idea on how I can avoid this imbalance? I tried putting a 0 value, but honestly, I don't really know what i'm doing, I've seen it in another function from serkanp.

Also, they may or may not have a callback, so, I guess this could also be a source of imbalance if there isn't anything in place of a callback ?

scarboni

  • Posts: 32
OK ! I may be onto something. User is an int pointer, and it was set as a void everywhere until now. I don't know yet if it works well, but it seems that putting a 0, and setting it as an int64, stop the crashes !

Ian @ un4seen

  • Administrator
  • Posts: 23311
That sounds like your app is 64-bit but your callback functions had a 32-bit "user" parameter. The callback "user" parameters should be a pointer or have the same size as a pointer, ie. something 32-bit if your app is 32-bit or something 64-bit if your app is 64-bit. That means the "int64" solution won't work with a 32-bit app. Does your programming language have a pointer type? If not, perhaps it has something like an "intptr" type, like in .Net?

scarboni

  • Posts: 32
Mac os does not support 32 bit anymore in its latests versions

There is no native pointer in node, but there is a way to fake them, it looks like c style pointer, but I'm not yet really familiar with this package https://www.npmjs.com/package/ref-napi

A part from being a pointer to an int, I don't know what may be an intptr?
With my fix, I have been able to make it works so far, but I think I may have the same issue when I have function with optional callback, to which I give null instead of a callback. I don't know much what I can give instead of null, but will try a few things

scarboni

  • Posts: 32
I found  fix for that issue ! I could set them as "pointer", which is what they are, so far, there aren't any more segfault.

Thank you !