neon1 Posted November 13, 2018 Report Share Posted November 13, 2018 Hello, I've been troubleshooting a memory corruption issue triggered by keyboard events in a TextEdit widget after gwinSetText() has been used on it. It is probably the same issue described a bit cryptically here: https://community.ugfx.io/topic/415-keyboard-and-textedit-problem/. Of course, as a µGFX newbie I may be simply misunderstanding something, so in that case feel free to tell me off. Reproduction: Create a TextEdit widget. Type some text into it using the (virtual) keyboard. Clear the widget's text by calling gwinSetText(ghTextedit, NULL, FALSE), without changing the focus. Do not tap/touch the TextEdit widget at this point. Type another character => memory corruption (likely causing a crash/hang/whatever). Analysis: Looking at gwin_textedit.c, the cause seems to be that the TextEdit widget does not learn of the fact that its text buffer has been replaced, and thus does not update/reset its cursorPos. cursorPos may then point at a position beyond the new buffer, causing memory corruption the next time a character is inserted or deleted. If the user taps the TextEdit widget after the text has been set and before typing again, the cursorPos is reset to a reasonable value and the issue does not appear. Workaround: Do not use gwinSetText() on TextEdit, but recreate the widget instead. Fix: A clean fix with proper cursorPos resetting would probably require TextEdit to be notified of text changes. A sort-of fix by checking cursorPos before using it is attached. Thanks for creating and maintaining µGFX! It's the best GUI library of its kind that I've come across, and the out-of-the-box virtual keyboard is a killer feature ? – Manuel patch-textedit-cursorpos.diff Link to comment Share on other sites More sharing options...
inmarket Posted November 13, 2018 Report Share Posted November 13, 2018 Thanks. I will look closely at that asap and update the repository accordingly. Link to comment Share on other sites More sharing options...
wctltya Posted November 14, 2018 Report Share Posted November 14, 2018 (edited) @neon1 Have you tried instead of passing NULL pointer here gwinSetText(ghTextedit, NULL, FALSE), to pass a pointer to a char buff, which first element is 0, or just gwinSetText(ghTextedit, "", FALSE) ? Edited November 14, 2018 by wctltya Link to comment Share on other sites More sharing options...
neon1 Posted November 14, 2018 Author Report Share Posted November 14, 2018 42 minutes ago, wctltya said: @neon1 Have you tried instead of passing NULL pointer here gwinSetText(ghTextedit, NULL, FALSE), to pass a pointer to a char buff, which first element is 0, or just gwinSetText(ghTextedit, "", FALSE) ? Yes, but as can be seen on line 525 of gwin_widget.c (µGFX v2.8), both are treated the same: if (!text || !*text) gw->text = ""; Link to comment Share on other sites More sharing options...
inmarket Posted November 17, 2018 Report Share Posted November 17, 2018 This has now been updated into the repository. Thanks for finding it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now