Microchip-MPLAB-Harmony / gfx

Harmony 3 Graphics library
https://microchip-mplab-harmony.github.io/gfx/
Other
16 stars 15 forks source link

laWidget_Delete doesn't work & causes reset #3

Open LuisCRSousa opened 5 years ago

LuisCRSousa commented 5 years ago

I've tried laWidget_Delete and laWidget_DeleteAllDescendants and it all causes system reset.

I've tried to debug and it seems libaria tries to paint the object again after released his memory. - Not sure

Call stack: runtime exception @ pc address 0x9d02d968 function and line number unavailable

LuisCRSousa commented 4 years ago

This issue is still present

LuisCRSousa commented 4 years ago

It only works if I call laWidget_RemoveChild before laWidget_Delete

microchip-gfx commented 4 years ago

Due to Harmony's non-blocking nature it is possible for the application to manipulate the graphics state while the graphics library is trying to perform work. It could be in the middle of event processing or painting a frame. The application would likely become unstable if a widget is in the middle of painting and it gets deleted by the application.

The "laContext_IsDrawing" function is provided in order to query the engine state. Manipulation of the state should only occur when this function returns 'false'.

If you're sure the engine isn't performing work and the crash still occurs then it could be a bug in the system.

LuisCRSousa commented 4 years ago

Found a tricky situation still regarding this case. Sometimes (depending on what I have on the screen at the time, really randomly), if I delete a lawidget that contains a labutton inside (deletion triggered with this button), the panel disappears successfully without problem. But, afterwards, if I click in the display zone where the button existed before deleting it's parent, the program breaks.

laContext_IsDrawing is returning false before I proceed with the widget deletion.

Found that if I coment line 507-508 of libraria_context.c this problem don't happen. if(_activeContext->focus != NULL) _activeContext->focus->focusLost(_activeContext->focus);

It looks like harmony is trying to focusLost on a object that don't exist anymore.

LuisCRSousa commented 4 years ago

Solution

Insert the following lines at _laWidget_Destructor at libaria_widget.c inside childrens for-loop to null focus function.

if(laContext_GetActive()->focus == child || laContext_GetActive()->focus == wgt) laContext_GetActive()->focus = NULL;