Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widget handler - segmentation fault #230

Closed
GregCornis opened this issue Dec 17, 2024 · 3 comments
Closed

Widget handler - segmentation fault #230

GregCornis opened this issue Dec 17, 2024 · 3 comments

Comments

@GregCornis
Copy link

I'm trying to add a switch in the PSDK settings shown in DJI Pilot. However, the app crashes instantly as soon as I click the switch (in DJI Pilot). From the code, none of GetWidgetValue and SetWidgetValue are being called. The config path works correctly because I see the switch in the parameters, I just can't click it. Do you have any idea what is the problem?

Here is my code:

static int32_t s_widgetValueList[1] = {0};

static T_DjiReturnCode DjiTestWidget_SetWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t value,
                                                    void *userData)
{
    
    USER_LOG_INFO("Set widget value, widgetType = %s, widgetIndex = %d ,widgetValue = %d",
                  widgetType, index, value);
    s_widgetValueList[index] = value;

    return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_DjiReturnCode DjiTestWidget_GetWidgetValue(E_DjiWidgetType widgetType, uint32_t index, int32_t *value,
                                                    void *userData)
{
    *value = s_widgetValueList[index];

    return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}


static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = {
    {1, DJI_WIDGET_TYPE_SWITCH,        DjiTestWidget_SetWidgetValue, DjiTestWidget_GetWidgetValue, NULL}
};

const uint32_t numberHandlers =  sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem);

T_DjiReturnCode setupWidget() {
    T_DjiReturnCode djiStat = DjiWidget_Init();
    if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Dji test widget init error, stat = 0x%08llX", djiStat);
        return djiStat;
    }

    djiStat = DjiWidget_RegDefaultUiConfigByDirPath("/path/to/widget_config");
    if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Couldn't register config dir, stat = 0x%08llX", djiStat);
        return djiStat;
    }
    djiStat = DjiWidget_RegHandlerList(s_widgetHandlerList, numberHandlers);
    if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Couldn't add handler list, stat = 0x%08llX", djiStat);
        return djiStat;
    }

    djiStat = DjiWidgetFloatingWindow_ShowMessage("Hello there");
    if (djiStat != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Couldn't set message, stat = 0x%08llX", djiStat);
        return djiStat;
    }
    return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

And the widget_config.json

{
  "version": {
    "major": 1,
    "minor": 1
  },
  "main_interface": {
    "floating_window": {
      "is_enable": true
    },
    "speaker": {
      "is_enable_tts": false,
      "is_enable_voice": false
    },
    "widget_list": []
  },
  "config_interface": {
    "widget_list": [
      {
        "widget_index": 1,
        "widget_type": "switch",
        "widget_name": "Enable laser trigger"
      }
    ]
  }
}
@dji-dev
Copy link
Contributor

dji-dev commented Dec 18, 2024

Agent comment from Leon in Zendesk ticket #124773:

Hello, it may be difficult to troubleshoot simply by looking at the program. We recommend that you use GDB debugging, which will make it clearer where your code crashes and is more conducive to troubleshooting and debugging.

°°°

@GregCornis
Copy link
Author

Thanks, I fixed it, it was an issue with USER_LOG_INFO (passed an int to render as %s)

@dji-dev
Copy link
Contributor

dji-dev commented Dec 20, 2024

Agent comment from Leon in Zendesk ticket #124773:

Hello, I'm glad that your problem has been solved. You're welcome. This is a problem with code writing or code implementation. If you have similar problems in the future, we suggest that you provide us with the output of GDB debugging or the code snippet where you reported the error so that we can better confirm it for you.

°°°

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants