Skip to content

Segmentation vault keyboard_client when used in superstate #119

@dave992

Description

@dave992

Description

I am consistently getting segmentation faults when using the keyboard client and the CbDefaultKeyboardBehavior when its started in a super state.

Overview

I have the following setup running (simplified for this issue):

  • SuperState1
    • InnerState1
    • InnerState2
    • InnerState3
  • NextState1
  • NextState2
  • ErrorState

SuperState1

In SuperState1 I defined a transition to be able to cancel the super state using the keyboard_client as well as a transition from the last inner state to NextState1. This means I had the following transition table:

typedef mpl::list<
  Transition<EvCbSuccess<CbInnerState3, OrReconstruction>, NextState1, SUCCESS>,
  Transition<EvKeyPressX<CbDefaultKeyboardBehavior, OrKeyboard>, ErrorState, ABORT>>
reactions;

And as we need the keyboard client behavior to create the transition events I added the following staticConfigure definition for SuperState1:

static void staticConfigure()
{
  configure_orthogonal<OrKeyboard, CbDefaultKeyboardBehavior>();
}

SuperState1 automatically starts InnerState1 which transitions to InnerState2 after completing a custom client behavior (not related to the keyboard client)

InnerState2

In InnerState2 I wait for user confirmation before transitioning to InnerState3. Initially I had the following transition table and staticConfigure definition:

// TRANSITION TABLE
typedef mpl::list<
  Transition<EvKeyPressN<CbDefaultKeyboardBehavior, OrKeyboard>, StiStopReconstruction, SUCCESS>
>reactions;

// STATE FUNCTIONS
static void staticConfigure()
{
  configure_orthogonal<OrKeyboard, CbDefaultKeyboardBehavior>();
}

After the transition to InnerState3 we automatically move to NextState1 as defined in SuperState1.

NextState1

I again wait for user confirmation in this state before moving to the next state. Resulting in the following transition table and staticConfigure definition:

// TRANSITION TABLE
typedef mpl::list<
  Transition<EvKeyPressU<CbDefaultKeyboardBehavior, OrKeyboard>, NextState2, SUCCESS>
>reactions;

// STATE FUNCTIONS
static void staticConfigure()
{
  configure_orthogonal<OrKeyboard, CbDefaultKeyboardBehavior>();
}

Once I try to trigger the state transition to NextState2 by pressing u I consistently receive a segmentation fault on:

Observed behavior

I noticed that after InnerState2 was started the keyboard client would send 1 log message to my terminal while I would receive 2 log messages from the client behavior(s). My first thought was that this could trigger the transition to NextState1 twice and maybe cause the segmentation fault during the second trigger.

  • Is this actually possible? I thought it might be as the transition table does not contain any info that allows it to see from which copy of the client behavior the event was received. In other words, it is not able to see the difference from the client behavior created in its own state vs the one created in the super state.

I tried the following to resolve this:

Attempt 1

Not starting the keyboard client behavior in InnerState2 by commenting out the configure_orthogonal<OrKeyboard, CbDefaultKeyboardBehavior>(); This still resulted in the segmentation fault.

My rationale was that I do not need it in here if it is still active from SuperState1 and would therefore not result in possibly two transitions being triggered. After this change, I no longer received 2 log messages from the client behaviors but only 1 as expected.

Attempt 2

Not starting the keyboard client behavior in the SuperState1 by commenting out the configure_orthogonal<OrKeyboard, CbDefaultKeyboardBehavior>();. This no longer results in any segmentation faults.

This would however also mean that during InnerState1 and InnerState3 I have no means of canceling unless I also add the client behaviors there.

┆Issue is synchronized with this Jira Task by Unito

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions