pmaillot / X32-Behringer

This GIT repo (C language) holds applications and utilities for the Behringer X32 and M32 mixing consoles. Additional details, documentation, implementation examples and apps can be found in my website:
https://sites.google.com/site/patrickmaillot/x32
234 stars 41 forks source link

X32 Simulator - crashes with "Segmentation fault: 11" #23

Closed digitalmomente closed 2 years ago

digitalmomente commented 2 years ago

Dear Patrick, first of all I would like to thank you for your great piece of software! I'm using your X32 simulator to develop an interface for the Behringer digital Mixers of the X series. Personally, I don't own a Behringer so it's great to have this simulator. The connection works fine so far, but unfortunately I have the problem that the simulator often disconnects. As an error it reports: "Segmentation fault: 11". Do you have any idea what could be causing this?

Best regards from Hamburg Olaf Claussen

Bildschirmfoto 2022-05-16 um 09 25 21
pmaillot commented 2 years ago

Olaf,

Sorry the program crashes, but it generally does so because of a lack or init file (the file created with a /shutdown command). There can be many other reasons though... for example, the command with 'button4' at the top of your log file is very suspicious, and a bad command generates invalid function pointers for the program parser, hence a crash.

I'd look into this area first.

-Patrick

Le mer. 25 mai 2022 à 20:00, digitalmomente @.***> a écrit :

Dear Patrick, first of all I would like to thank you for your great piece of software! I'm using your X32 simulator to develop an interface for the Behringer digital Mixers of the X series. Personally, I don't own a Behringer so it's great to have this simulator. The connection works fine so far, but unfortunately I have the problem that the simulator often disconnects. As an error it reports: "Segmentation fault: 11". Do you have any idea what could be causing this?

Best regards from Hamburg Olaf Claussen

[image: Bildschirmfoto 2022-05-16 um 09 25 21] https://user-images.githubusercontent.com/34488506/170331352-286287ad-0410-4ff6-983d-00aa9f9deb97.png

— Reply to this email directly, view it on GitHub https://github.com/pmaillot/X32-Behringer/issues/23, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZZT7VVYFLQT6CVJUEVXWTVLZTD3ANCNFSM5W554ABQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

digitalmomente commented 2 years ago

Dear Patrick, thank you very much for your quick reply. I'm sorry for confronting your simulator with requests that aren't always entirely compliant. The first line is a placeholder that was not set at the time of execution. If you need assistance reproducing the crash, please feel free to get in touch. I also think that this is somehow related, even if it doesn't appear in the log in a chronological context.

pmaillot commented 2 years ago

It's actually the /bus/5/... command that created the segfault. /bus/ is expecting a two-digit value after the / Fixed in rel. 0.84

digitalmomente commented 2 years ago

Awesome! Thank you very much. Unfortunately there is another command that quits the simulator. Please have a loook at

->X, 28 B: /ch/07/preamp/rtntrim~,~ Segmentation fault: 11

What do you think?

pmaillot commented 2 years ago

That command does not exist. It’s /ch/xx/preamp/trim that you should be using.

Remember X32 is a console ‘emulator’ created so I could test application programs while on the go. SO a seg fault was/is to me just as effective as an error message, especially when it comes to non compliant or non existing commands.

-Patrick

Edit: This said, there was an inconsistency in the array lengths for channel/01 vs. all others (02..32), so I fixed this as well, as this was the actual reason for the crash, and not the non-existing command. :) Thanks for finding this bug.

digitalmomente commented 2 years ago

This hint is good. It allows me to classify future "faults" better. Thank you!

I'm building an IOS app with which you can create freely definable panels with buttons, sliders and so on. The wrong command comes from an interface that a friend of mine made. He uses my app to build small optimized surfaces for his Behringer X18, which he can then use while making music on stage or as a DJ. Unfortunately, I have little experience with the Berhinger audio mixing consoles by myself.

But you have already helped me a lot with your emulator! My interface already works bi-directionally with the mixers. Maybe you would like to take a look at www.devicejockey.de You can also download the app yourself as a beta. My friend thinks the app is great. He says it opens up opportunities that Behringer itself doesn't offer. What do you think?

Best regards from Hamburg

pmaillot commented 2 years ago

Hello Olaf,

Be aware the X-Air series commands are not fully compatible with X32 mixers family... So even if the X32 emulator 'helps', it cannot be used to validate your app is compliant with an X-Air device. As far as testing your app, I am an Android user, so no go for me.

-Patrick

digitalmomente commented 2 years ago

Dear Patrick, Many thanks for your valuable tips!

Actually, I intended to send you a Mac-compiled version as a small thank you, but unfortunately the IP is not displayed after the start and I can't find the error. Xip-str is correctly set in getmyIP, but loses its value and reverts to "".

console Xip_str.txt getmyIP.txt

pmaillot commented 2 years ago

Hello,

That would be nice indeed 😊

For Mac, the function that reports the computer IP address is at line 1091:

void getmyIP() {

  struct ifaddrs *ifaddr, *ifa;

  int s;

  r_buf[0] = 0;

  if (getifaddrs(&ifaddr) == -1) {

         perror("getifaddrs");

         return;

  }

  for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {

         if (ifa->ifa_addr != NULL) {

               // use r_buf as we may need a large string

               if ((s = getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), r_buf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) == 0) {

// you typically have to replace "en0" by "wlan0", "eth0",... depending on your physical interface support

                      if ((strcmp(ifa->ifa_name,"en0") == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {

//printf("\tInterface : <%s>\n",ifa->ifa_name );

//printf("\t Address : <%s>\n", r_buf);

                            strcpy(Xip_str, r_buf); // update Xip_str

                      }

               }

         }

  }

  freeifaddrs(ifaddr);

  return;

}

If you go under debug, and set a breakpoint at the r_buf[0] = 0; line, you will find what your Mac returns as part of the call to getnameinfo()and set the comparison string value for the strcmp() call the line after; It’s likely the issue. Your Mac (or new macs) may not report “en0” as their default/main used IP name.

-Patrick

From: Olaf Claussen @.> Sent: Monday, May 30, 2022 9:08 AM To: pmaillot/X32-Behringer @.> Cc: Patrick-Gilles Maillot @.>; State change @.> Subject: Re: [pmaillot/X32-Behringer] X32 Simulator - crashes with "Segmentation fault: 11" (Issue #23)

Dear Patrick, Many thanks for your valuable tips!

Actually, I intended to send you a Mac-compiled version as a small thank you, but unfortunately the IP is not displayed after the start and I can't find the error. Xip-str is correctly set in getmyIP, but loses its value and reverts to "".

console Xip_str.txt https://github.com/pmaillot/X32-Behringer/files/8796205/console.Xip_str.txt getmyIP.txt https://github.com/pmaillot/X32-Behringer/files/8796250/getmyIP.txt

— Reply to this email directly, view it on GitHub https://github.com/pmaillot/X32-Behringer/issues/23#issuecomment-1140781272 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZZT7SAYTUZ5CBELQ33B23VMRSOFANCNFSM5W554ABQ . You are receiving this because you modified the open/close state. https://github.com/notifications/beacon/ADZZT7QFOYI7ODANXXESL5TVMRSOFA5CNFSM5W554AB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIP7PBWA.gif Message ID: @. @.> >

digitalmomente commented 2 years ago

Hi, i have made a breakpoint in the function and added some printf to debug. The strcpy is called exactly one time, when ifa_name is equal to "en0". "en0" is still used. But one or two rounds later, after Xip_str is set, Xip_str is an empty string again. Although strcpy is never called again. Please have a look in the console.txt, i have sent you as an attachment. There, you'll see, that Xip_str is set "Address successfully set: <192.168.178.128>" and then later gets empty again. The getmyIP.txt shows you the code, similar to your code above, with the printf inserted.

It's a bit weird and I'm not familiar enough to C+ What do I overlook?

pmaillot commented 2 years ago

I can't find/see the console.txt file. No big deal. If you continue after the breakpoint until the function returns, you will see where the IP string (Xip_str) is modified, it it is, and how it is used later on (around line 950) to set the program socket and bind the IP to it.

Do you get an error (such as: "Error on IP address") or do you get the message "Listening to port: %s, X32 IP =" with no IP data?

digitalmomente commented 2 years ago

I get the second one: "X32 - v0.84 - An X32 Emulator - (c)2014-2019 Patrick-Gilles Maillot Listening to port: 10023, X32 IP = Reading init file... Done"

No error.

Look at this:

X32 - v0.84 - An X32 Emulator - (c)2014-2022 Patrick-Gilles Maillot actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> Address successfully set: <192.168.178.128> actual Address in for loop: <192.168.178.128> actual Address in for loop: <192.168.178.128> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> actual Address in for loop: <> determined Address after for loop: <>

"actual Address in for loop ... " is printed every round in the for loop, line 1114

"Address successfully set: <192.168.178.128>" is only printed one time, after Xip_str is set with strcpy(Xip_str, r_buf), line 1110

"determined Address after for loop: <>" is printed just before the return of the function "getmyIP", line 1119

I do not understand, why the value of Xip_str is cleared, after it is set ?

My Code is similar to yours, except the printf's:

void getmyIP(void) {

struct ifaddrs *ifaddr, *ifa;
int s;

r_buf[0] = 0;

if (getifaddrs(&ifaddr) == -1) {
    perror("getifaddrs");
    return;
}
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
    if (ifa->ifa_addr != NULL) {
        // use r_buf as we may need a large string
        if ((s = getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), r_buf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) == 0) {

// you typically have to replace "en0" by "wlan0", "eth0",... depending on your physical interface support if ((strcmp(ifa->ifa_name,"en0") == 0) && (ifa->ifa_addr->sa_family == AF_INET)) { //printf("\tInterface : <%s>\n",ifa->ifa_name ); //printf("\t Address : <%s>\n", r_buf); strcpy(Xip_str, r_buf); // update Xip_str printf("\t Address successfully set: <%s>\n", Xip_str); } } } printf("\t actual Address in for loop: <%s>\n", Xip_str); } printf("\t determined Address after for loop: <%s>\n", Xip_str); freeifaddrs(ifaddr); return; }

pmaillot commented 2 years ago

OK, It would probably be a good idea to break the for loop as soon as Xip_str[] is set with the call to strcpy(); This way we're sure there are no interactions or interferences from other parts of the code, and the value found should therefore be maintained for later use. You could for ex. change the code to:

void getmyIP() {

    struct ifaddrs *ifaddr, *ifa;
    int s;

    r_buf[0] = 0;

    if (getifaddrs(&ifaddr) == -1) {
        perror("getifaddrs");
        return;
    }
    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
        if (ifa->ifa_addr != NULL) {
            // use r_buf as we may need a large string
            if ((s = getnameinfo(ifa->ifa_addr,sizeof(struct sockaddr_in), r_buf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) == 0) {
// you typically have to replace "en0" by "wlan0", "eth0",... depending on your physical interface support
                if ((strcmp(ifa->ifa_name,"en0") == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
 //printf("\tInterface : <%s>\n",ifa->ifa_name );
 //printf("\t Address : <%s>\n", r_buf);
                    strcpy(Xip_str, r_buf); // update Xip_str
                    freeifaddrs(ifaddr);
                    return;
                }
            }
        }
    }
    freeifaddrs(ifaddr);
    return;
}

let me know how this goes.

digitalmomente commented 2 years ago

Good idea! That works until now :-)) My app is able to connect to the simulator and interacts with it.

I have added the compiled as attachment to this post. Do you see it? Do you have anybody who can run this version on his mac?

Attachement: X32_v084_mac_oc.zip

pmaillot commented 2 years ago

Got it! I'll put the version into my website. Thanks!

digitalmomente commented 2 years ago

Your welcome. Thank you for our conversation!

pmaillot commented 2 years ago

That command does not exist. It’s /ch/xx/preamp/trim that you should be using.

Remember X32 is a console ‘emulator’ created so I could test application programs while on the go. SO a seg fault was/is to me just as effective as an error message, especially when it comes to non compliant or non existing commands.

-Patrick

From: Olaf Claussen @.> Sent: Friday, May 27, 2022 1:29 PM To: pmaillot/X32-Behringer @.> Cc: Patrick-Gilles Maillot @.>; State change @.> Subject: Re: [pmaillot/X32-Behringer] X32 Simulator - crashes with "Segmentation fault: 11" (Issue #23)

Awesome! Thank you very much. Unfortunately there is another command that quits the simulator. Please have a loook at

->X, 28 B: /ch/07/preamp/rtntrim~,~ Segmentation fault: 11

What do you think?

— Reply to this email directly, view it on GitHub https://github.com/pmaillot/X32-Behringer/issues/23#issuecomment-1139531910 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZZT7QBVFBAKGGNG4DS4YTVMCWYPANCNFSM5W554ABQ . You are receiving this because you modified the open/close state. https://github.com/notifications/beacon/ADZZT7R5BSMADNJ3WFKDX2TVMCWYPA5CNFSM5W554AB2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIPV6BBQ.gif Message ID: @. @.> >