Thursday, June 29th 2017, 9:17am UTC+2

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 33

1

Thursday, June 15th 2017, 5:26am

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/C++ Source code

1
2
char String[150];
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/C++ Source code

1
char String[150] = "TEST";


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

C/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

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 33

2

Thursday, June 15th 2017, 6:32am

Okay, I did another test, in the callback of LISTBOX,
calling LISTBOX_GetItemText() also cause crashed,
reason unknown.

Who can shed me some light of hope?
Thanks in advance!

Kenmux

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 33

3

Thursday, June 15th 2017, 10:57am

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/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

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 33

4

Friday, June 16th 2017, 5:33am

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

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 309

5

Friday, June 16th 2017, 4:55pm

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

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 33

6

Saturday, June 17th 2017, 8:34am

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