Memory type for `font_name` in `NvOSD_FontParams`

• DeepStream Version: 6.3
• TensorRT Version: 8.5
• NVIDIA GPU Driver Version: 535
• Issue Type: question

The NvOSD_FontParams struct has this definition:

typedef struct _NvOSD_FontParams {
  char * font_name;             /**< Holds a pointer to the string containing
                                 the font name. To display a list of
                                 supported fonts, run the fc-list command. */

//  char font_name[64];         /**< Holds a pointer to a string containing
//                               the font name. */

  unsigned int font_size;       /**< Holds the size of the font. */

  NvOSD_ColorParams font_color; /**< Holds the font color. */
} NvOSD_FontParams;

Since font_name is not a const pointer, it makes me think I should allocate dynamic memory for it. Which of these options is correct?

  • Option 1
  const char *nv_osd_font_name = "Serif";
  text_params.font_params.font_name = const_cast<char *>(nv_osd_font_name);
  • Option 2
  const char *nv_osd_font_name = "Serif";
  text_params.font_params.font_name = strdup(nv_osd_font_name);

You can refer to our source code, like:

static gchar font_name[] = "Serif";
text_params.font_params.font_name = font_name;


txt_params->font_params.font_name = (char *)"Serif";

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.