LISTBOX_GetItemText() in LISTBOX user draw function cause crashed

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • LISTBOX_GetItemText() in LISTBOX user draw function cause crashed

    Hello all,

    Now I ran into a very annoying issue:

    The code always crashed when calling LISTBOX_GetItemText() in LISTBOX user draw function.
    All I known is that, the code is inherited from an earlier project which works very well.

    When I look into this issue, I found this is the reason:

    C Source Code

    1. char String[150];
    2. LISTBOX_GetItemText (hWin, pDrawItemInfo->ItemIndex, String, sizeof (String));


    I comment them, and fill the char array "String" with const string, everything works very well:

    C Source Code

    1. char String[150] = "TEST";


    I do add strings to the LISTBOX before setting user draw function:

    C Source Code

    1. LISTBOX_AddString (hObj, UI_StringTable[StringId]);


    Also, if I don't use user draw function, everything also runs well.
    The strings displayed are just the ones I added.

    So, the problem is, where goes wrong?
    How can I tell whether the strings attached to the LISTBOX or not?
    My emWin version is v5.4.0. Any ideas? Thanks in advance.

    Kenmux
  • Well, I took place the library file with source codes and looked into this issue.

    But, it still seems not that easy to find the problem.

    I focused on the function LISTBOX_GetItemText() and the code crashed on this line:

    C Source Code

    1. GUI__MEMCPY(pBuffer, pString, CopyLen);


    But it seems that all local variables are sane:



    Then where goes wrong? Just confused...
    Any ideas?

    Thanks,
    Kenmux
  • Okay, a further step:
    1) GUI__MEMCPY links to memcpy which causes crash
    2) there's an optional replacement for memcpy which test good: GUI__memcpy

    So, can I replace memcpy with GUI__memcpy globally? Any potential risks?
    Similarly, GUI__memset vs memset?

    Also, the reason why memcpy caused crash unknown.

    Who can give some clear answers, thanks in advance.

    Kenmux
  • Hi,

    If memcpy crashes, we can't do much. Also, I can't say why it crashes.

    You can set a custom memcpy routine. Simply add something like this to your GUIConf.h (since it is a preprocessor define, you would need to rebuild the library):

    #define GUI_MEMCPY GUI__memcpy

    Regards,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Sven,

    Thanks for your reply.
    Yes I do that in the header file "GUI_ConfDefaults.h".
    And the library file re-created works very well now.
    I hope there's no potential risk, please!!!

    Thanks,
    Kenmux