›

bug in C++ layer (null pointer)

To
reproduce, compile the Metwear-CppAPI with debug enabled 
(Compiled
as UWP library and added a reference to it from the C++ lib).

Then use the
CS template to log accel + gyro data (100 Hz). 

We also
have an GPIO signal going in parallel too that we use to stop logging.

 As you can see in the
screenshot, it crashes often in the C++ layer with a null pointer exception at
state->create_next(..)

image


https://ibb.co/eeubrQ

Comments

  • edited May 8
    Hmm, might be memory corruption in your C++ lib... (weird values in *state).

  • edited May 8
    Please post the MetaWear code you are running.  Also, when does this error occur and does it consistently happen?
  • It happens very consistently after two/three secs of logging.

    Preudocode:

    click-button-handler() {
           setup-logging-signals
           while (1) {
    start-logging
    delay 2 secs
    stop-logging
    }
    }

    setup_logging_signals() {
    }

    start_logging() {
                    mbl_mw_logging_clear_entries(getBoard());
                    mbl_mw_logging_start(getBoard(), 1);

                    if (useAccel)
                    {
                        mbl_mw_acc_enable_acceleration_sampling(getBoard());
                        mbl_mw_acc_start(getBoard());
                    }

                    if (useGyro)
                    {
                        mbl_mw_gyro_bmi160_enable_rotation_sampling(getBoard());
                        mbl_mw_gyro_bmi160_start(getBoard());
                    }    
    }


  • void stop_logging() {
                    if (useGyro)
                    {
                        mbl_mw_gyro_bmi160_stop(getBoard());
                        mbl_mw_gyro_bmi160_disable_rotation_sampling(getBoard());
                    }

                    if (useAccel)
                    {
                        mbl_mw_acc_stop(getBoard());
                        mbl_mw_acc_disable_acceleration_sampling(getBoard());
                    }

                    mbl_mw_logging_stop(getBoard());
    }
  • with setup_signals:
                mbl_mw_logging_clear_entries(getBoard());
                mbl_mw_metawearboard_set_time_for_response(getBoard(), 500);
                
                IntPtr accSignal = getAccSignal(false);
                IntPtr gyroSignal = getGyroSignal();

                config_acc(accSignal);
                config_gyro(gyroSignal);
                setup_GPIO();

                var logAccFn = new Fn_IntPtr((IntPtr _accLogger) =>
                {
                    accLogger = _accLogger;
                    if (accLogger.ToInt64() != 0)
                    {
                        mbl_mw_logger_subscribe(accLogger, accDataHandler);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("ERROR: failed to create the acc-logger");
                    }
                });

                var logGyroFn = new Fn_IntPtr((IntPtr _gyroLogger) =>
                {
                    gyroLogger = _gyroLogger;
                    if (gyroLogger.ToInt64() != 0)
                    {
                        mbl_mw_logger_subscribe(gyroLogger, gyroDataHandler);
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("ERROR: failed to create the gyro-logger");
                    }
                });

                if (useAccel)
                    mbl_mw_datasignal_log(accSignal, logAccFn);
                if (useGyro)
                    mbl_mw_datasignal_log(gyroSignal, logGyroFn);

  • (shortened as much as possible, removed printlns and such)

  • I cannot reproduce this bug on my side with VS2017.  Have you tried using the DLLs hosted on Nuget?  

    Also, what VS are you using and are you running your UWP app on a desktop or perhaps a Pi?
  • Hi Eric, 

    tried this on a win 10 desktop with latest patches, VS2017, DLL from nuget originally. Compiled the metawear C++ lib locally to get debugging going. Accel, gyro are logging simultaneously, a GPIO subscription set up before logging starts. It looks like a BLE packet arrives, its processed and then added to some list in your C++ layer. There is breaks. Is there perhaps a race condition in adding objects to this list? This makes reproducing it hard unfortunately, its the nature of race conditions...
  • edited May 15
    Hi Eric, 

    I've a better idea: I created a minimal version of the app that still reproduces it.
    Simply press the start-logging button and see it crash in the C++ layer.

    Where can I upload the source code to/email it to?

    Best regards, 
    Ronald.
  • Put it on GitHub
  • App says i need to copy a 'loops.json' file to the 'LocalState' folder.
  • Hi Eric, 

    missed some code while doing minimization. Removed it now. Can you try again?

    Cheers,
    Ronald.
  • I am able to run your app and create a csv file.  Try decreasing the max connection interval to 7.5ms or increase the time for response to 1000ms.
  • Hi Eric, 

    good to see that you've got it running. I assume that you've clicked start/stop streaming which works ok here as well. 

    Now please press 'start logging' and see the crash. Windows should popup an info box saying that memory is corrupted. When you look closer in visual studio with debug enabled you'll see it happening in your C++ layer.

    Cheers,
    Ronald.
  • edited May 23
    No, I can run logging just fine on my PC.  As previously mentioned, try decreasing the max connection interval or increasing the time for response.

    You should give MetaBase a try and see if it also crashes when trying to log data:
Sign In or Register to comment.