Hot!laLabelWidget_SetText causes crash

Author
rbmisc
Starting Member
  • Total Posts : 73
  • Reward points : 0
  • Joined: 2017/07/19 08:22:06
  • Location: 0
  • Status: offline
2017/08/10 11:16:26 (permalink)
0

laLabelWidget_SetText causes crash

I have implemented the following code from aria_counter example into my application:
laString str;
sprintf(charBuff, "%u", tickCount--);
str = laString_CreateFromCharBuffer(charBuff, GFXU_StringFontIndexLookup(&stringTable, string_NewTxt, 0));
laLabelWidget_SetText(LabelWidget2, str);
laString_Destroy(&str);
laWidget_Invalidate((laWidget*)LabelWidget2);
 
laLabelWidget_SetText(LabelWidget2, laString_CreateFromID(string_InitialText)) is called before looping through the above code to initialize it to a particular string. This is called when a button is pressed to start the looping. Works fine the first time the button is pressed, i.e. the label gets updates as its supposed to. But pressing the button a second time, the label updating starts then the application crashes.
 
When I remove initializing the text between looping through the above code or use something similar to the above code to initialize the label, the app doesn't crash.
 
I get the following message in Call Stack when it crashes:
Runtime exception @ PC address 0x9d08f96c. Function and line number unavailable.    at   : 0
 
I have found that it's laString_Copy function in laLableWidget_SetText is causing the crash.  This is as much debugging I have done so far.
 
I'm using Harmony 2.03b and the graphics controller is PIC32MZ2064DAG176.
 
Also, I see that laWidget_Invalidate((laWidget*)lbl) is done in laLabelWidget_SetText(laLabelWidget* lbl, laString* str) function.  So it appears that laWidget_Invalidate((laWidget_Invalidate((laWidget*)LabelWidget2) isn't needed in the above code.
 
 
 
 
 
#1

12 Replies Related Threads

    Ed@Microchip
    Junior Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2017/08/10 17:01:03 (permalink)
    0
    Hi rbmisc,
     
    We're still debugging this, there might be some issue when using both laString_CreateFromCharBuffer() and laString_CreateFromID() to update the same label.
     
    In the meantime, can you try using laString_CreateFromCharBuffer() to initialize the string? You can pass string_InitialText for the string ID.
     
    Thanks
     
    Ed@Microchip
    #2
    Ed@Microchip
    Junior Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2017/08/10 17:12:29 (permalink)
    0
    Hi rbmisc,
     
    I'm seeing a different failure than what you are reporting. I'm not seeing a crash, but the label fails to update after re-initializing it with a string created by laString_CreateFromID().
     
    I'm able to fix this by adding the line in BOLD to laString_Copy():
     

         if(src->length == 0 && dst->data != NULL)
         {
             laContext_GetActive()->memIntf.heap.free(dst->data);
            dst->data = NULL;
     
     
     
            return LA_SUCCESS;
         }
     
     
     

     
    Can you try this? And also, try increasing your application's heap.
     
    Let me know how it works.
     
    Thanks,
     
    Ed@Microchip
    post edited by Ed@Microchip - 2017/08/10 17:14:24
    #3
    rbmisc
    Starting Member
    • Total Posts : 73
    • Reward points : 0
    • Joined: 2017/07/19 08:22:06
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2017/08/11 04:27:12 (permalink)
    0
    Ed,
    That appears to have fixed the problem.  I have tried several consecutive times and no failure.  My definition of crashing the program is that it halts as indicated in debug mode.
     
    The heap size is 102400.  Does it need to be bigger?
    Rick 
    #4
    Ed@Microchip
    Junior Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2017/08/11 09:01:29 (permalink)
    0
    Hi Rick,
     
    Glad to know that it fixed the issue. No, you don't need to increase the heap if its working. 
     
    Thanks,
     
    Ed@Microchip
    #5
    Ed@Microchip
    Junior Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2017/08/11 09:03:20 (permalink)
    3 (1)
    Additional note - Harmony 2.04 is already closed, so the fix for this issue will go to version 2.05. Please continue using the suggested fix above until 2.05 is released.
    #6
    kuku
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2012/03/03 08:05:54
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2018/01/12 05:31:00 (permalink)
    0
    I think that I find something similar. I add to my screen several changing value. App will crash or my vaule was blink or vanish afer some time (~20sec?)
     
     
    (code is ugly, I search reason)
     
    void Redraw_ProcessSettings(void)
    {
        char TextToSet[20];
        char i=0;
        laString laStr;
        laString_Initialize(&laStr);
        
        laContext* lang= laContext_GetActive(); //which language we use
     
        

        
         if(lang->languageID == language_English) //change position of some field
         {
             laWidget_SetPosition((laWidget*)BUT_EE_PWR_START, 53, 14);
             laWidget_SetPosition((laWidget*)BUT_EECoolOn, 59, 49);
             laWidget_SetPosition((laWidget*)BUT_EEFloodOn, 257, 49);
         }
     
        for(i=0; i<20; i++) TextToSet[i]=0;
        sprintf(TextToSet,"%d.%02d",EE.PreheatPwr/100, EE.PreheatPwr%100); 
        //laStr = laString_CreateFromCharBuffer(TextToSet, GFXU_StringFontIndexLookup(&stringTable, string_StringProcess_iPWR, 0));
        
        laStr = laString_CreateFromCharBuffer(TextToSet, &ArialBlackNormal);

        laButtonWidget_SetText(BUT_EE_PWR_START, laStr); // Update a TexEdit widget
        for(i=0; i<20; i++) TextToSet[i]=0;
        
        sprintf(TextToSet,"%d",EE.PreheatCoolOn); 
        laStr = laString_CreateFromCharBuffer(TextToSet, GFXU_StringFontIndexLookup(&stringTable, string_StringProcess_iPWR, 0));
        laButtonWidget_SetText(BUT_EECoolOn, laStr); // Update a TexEdit widget
        for(i=0; i<20; i++) TextToSet[i]=0;
        
        sprintf(TextToSet,"%d",EE.PreheatFloodOn); //
        laStr = laString_CreateFromCharBuffer(TextToSet, GFXU_StringFontIndexLookup(&stringTable, string_StringProcess_iPWR, 0));
        laButtonWidget_SetText(BUT_EEFloodOn, laStr); // Update a TexEdit widget
        for(i=0; i<20; i++) TextToSet[i]=0;
        
        
        
        //tmp=1234567891012312345611111111111111111111111111111111111111111111111111;
        
        sprintf(TextToSet,"%d",tmp);
        laStr = laString_CreateFromCharBuffer(TextToSet, GFXU_StringFontIndexLookup(&stringTable, string_Main_Tmp_default, 0));
        laTextFieldWidget_SetText(TextFieldWidget25, laStr); // Update a TexEdit widget

        laString_Destroy(&laStr);


    }

     
    and I see that line laStr = laString_CreateFromCharBuffer back me empty laStr. 
    More precisely, laString_CreateFromCharBuffer call laString_Allocate routine and they don't see str->data and back me faliure
     
     
     
     
    laString laString_CreateFromCharBuffer(const char* chr, GFXU_FontAsset* fnt)
    {
     laString str = { 0, 0, 0, 0, LA_STRING_NULLIDX };
        uint32_t len = 0;
        uint32_t i;
        
        if(laContext_GetActive() == NULL || chr == NULL)
        {
            laString_Initialize(&str);
            return str;
        }
        
        len = strlen(chr);
        
        if(len == 0)
            return str;
            
        laString_Allocate(&str, len);////////////////////////////////after this
        
        if(str.capacity == 0)///////////////////////////////////////////// I have still 0
            return str;
            
        for(i = 0; i < len; i++)
            str.data[i] = (GFXU_CHAR)chr[i];
        
        str.data[i] = '\0';
        
        str.font = fnt;
        str.table_index = LA_STRING_NULLIDX;
        
        return str;
    }

     
     
     
     
    laResult laString_Allocate(laString* str, uint32_t length)
    {
        if(laContext_GetActive() == NULL || str == NULL || length == 0)
            return LA_FAILURE;

        if(str->data != NULL)
            laContext_GetActive()->memIntf.heap.free(str->data);

        laString_Initialize(str);

        if(length == 0)
            return LA_SUCCESS;
        
        str->data = laContext_GetActive()->memIntf.heap.calloc(1, (length + 1) * sizeof(GFXU_CHAR));
        
        if(str->data == NULL)
            return LA_FAILURE;////////////////////////////////////////here I get falire
        
        str->capacity = length + 1;
        str->length = length;
        
        return LA_SUCCESS;
    }

     
    Also intersting me why MHGC in each code generator click want to change gfx.assets.c file. Not only one time after some change. I see that I have  dst->data= NULL in laString_Copy
     

     Also I think that it have influence for last use button (press/release it if I touch keyboard buttons). Sometime, it look like laStr don't take my char content.
    Somehere heap are not freeing and don't have place for new task? ;/
     
    what I can do now? harmony 2.05, device 2064DAH
    post edited by kuku - 2018/01/12 08:44:01
    #7
    Ed@Microchip
    Junior Member
    • Total Posts : 49
    • Reward points : 0
    • Joined: 2017/04/06 09:39:29
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2018/01/12 09:01:31 (permalink)
    0
    @kuku
     
    Does it always fail the first time laString_Allocate() is called or after several times? If it fails the first time, can you try increasing your heap? If it fails after several times, the memory may be getting fragmented. Either way, try increasing your heap to see if it helps.
    #8
    kuku
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2012/03/03 08:05:54
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2018/01/12 09:23:12 (permalink)
    0
    Redraw_ProcessSettings is called every 10ms. Harmony want for heap 60701. I give him 121402 now . How many not give him, then effect is the same (maybe bit later, I not mesure time to crash).
     
    ----
    and maybe it's debuger (optymization level) problem but all time debuger show me no data in str->data, after 
    str->data = laContext_GetActive()->memIntf.heap.calloc(1, (length + 1) * sizeof(GFXU_CHAR));

     
    No matter that it work proper or not. But only when I note crash, then each time go out with faliure from laString_Allocate
     
    if(str->data == NULL)
            return LA_FAILURE

     

     
    ----
    call every 100ms has the same result.
     
     
    post edited by kuku - 2018/01/13 02:56:31
    #9
    kuku
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2012/03/03 08:05:54
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2018/01/13 03:00:04 (permalink)
    0
     
    It look's like fixed- work without cause all night. I move laString declaration from function to top my file
    static laString laStr;

     
    In my display routine I use lit like this:
    sprintf(TextToSet,"%d",tmp);
        laString_Destroy(&laStr);
        laStr = laString_CreateFromCharBuffer(TextToSet, GFXU_StringFontIndexLookup(&stringTable, string_Main_Tmp_default, 0));
        laLabelWidget_SetText(TempKeg, laStr); // Update a TexEdit widget

     
    I will see what will be in future. I'm not sure why this is correct, why destroy not free the heap corectly...
    #10
    StefanK.
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2017/10/27 04:22:35
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2018/03/26 04:22:38 (permalink)
    0
    Hello @all,
    I use this thread 'cause I think I have a similar problem.
     
    In my app there is a list of 22 items. In the Item_Select_Screen are 5 buttons to select a item and a "Left-Button", a "Right-Button" and a "Home-Button". At start I fill the 5 buttons in the APP_Item_Page() function with the names of the first 5 items. When I press the right-button, I fill the buttons with the names of the second 5 items. This all works fine, I can go to the end of the ItemList and back to the start of the ItemList, no problems. When I go back to then main menu and then select the Item_Select Screen again, then the application crashes. There is only a white screen. In the debugger, the application goes to the general_exception_handler. I've find out that the problem is in the laResult laString_Copy(laString* dst, const laString* src) function, called from the laButtonWidget_SetText( ... ) function. I've doubled the heap from 100,000 to 256,000 bytes, nothing helps.
     
    #define MAXITEMS 22 // Itemcount

    const char * ItemList[MAXITEMS] = {"Item 1","Item 2","Item 3","Item 4","Item 5",
                                          ...
                                        "Item 22"};
                                        
    uint8_t ItemPage; // actual page


    void APP_ItemNextPage(void) // Called from the "Right"-button
    {
        ItemPage++; // next Page
    }

    void APP_ItemPreviousPage(void) // Called from the "Left"-button
    {
        ItemPage--; // previous page
    }


    void APP_Item_Page(uint8_t page)
    {
       laString newString;
       uint8_t count;
        
        count=0;
        
        if ((count+page*5)< MAXITEMS) // Is this the end of the ItemList
        {
            laWidget_SetEnabled((laWidget*)ButtonItem1,LA_TRUE); // Enable the first button
            laWidget_SetVisible((laWidget*)ButtonItem1,LA_TRUE); // Make the button visible
            
            laString_Initialize(&newString); // Initialize string

            // create string from ItemList
            newString = laString_CreateFromCharBuffer(ItemList[page*5+count], GFXU_StringFontIndexLookup(&stringTable,string_DummyString,0));
            laButtonWidget_SetText(ButtonItem1,newString); // Show string on button
            laString_Destroy(&newString); // Destroy string
        
        }
        else
        {
            laWidget_SetEnabled((laWidget*)ButtonItem1,LA_FALSE); // Disable button
            laWidget_SetVisible((laWidget*)ButtonItem1,LA_FALSE); // Hide button
        }
        
        count++; // Next item in list
        
        if ((count+page*5)< MAXITEMS) // Is this the end of the ItemList
        {
            laWidget_SetEnabled((laWidget*)ButtonItem2,LA_TRUE);
            laWidget_SetVisible((laWidget*)ButtonItem2,LA_TRUE); // See ButtonItem1
            
            laString_Initialize(&newString);


            newString = laString_CreateFromCharBuffer(ItemList[page*5+count], GFXU_StringFontIndexLookup(&stringTable,string_DummyString,0));
        
            laButtonWidget_SetText(ButtonItem2,newString);
            laString_Destroy(&newString);
        
        }
        else
        {
            laWidget_SetEnabled((laWidget*)ButtonItem2,LA_FALSE);
            laWidget_SetVisible((laWidget*)ButtonItem2,LA_FALSE);
        }
        
        count++;
        
        if ((count+page*5)< MAXITEMS)
        {
            laWidget_SetEnabled((laWidget*)ButtonItem3,LA_TRUE);
            laWidget_SetVisible((laWidget*)ButtonItem3,LA_TRUE); // See ButtonItem1
            
            laString_Initialize(&newString);

            newString = laString_CreateFromCharBuffer(ItemList[page*5+count], GFXU_StringFontIndexLookup(&stringTable,string_DummyString,0));
        
            laButtonWidget_SetText(ButtonItem3,newString);
            laString_Destroy(&newString);
        
        }
        else
        {
            laWidget_SetEnabled((laWidget*)ButtonItem3,LA_FALSE);
            laWidget_SetVisible((laWidget*)ButtonItem3,LA_FALSE);
        }
        
        count++;
        
        if ((count+page*5)< MAXITEMS)
        {
            laWidget_SetEnabled((laWidget*)ButtonItem4,LA_TRUE);
            laWidget_SetVisible((laWidget*)ButtonItem4,LA_TRUE); // See ButtonItem1
            
            laString_Initialize(&newString);

            newString = laString_CreateFromCharBuffer(ItemList[page*5+count], GFXU_StringFontIndexLookup(&stringTable,string_DummyString,0));
        
            laButtonWidget_SetText(ButtonItem4,newString);
            laString_Destroy(&newString);
        
        }
        else
        {
            laWidget_SetEnabled((laWidget*)ButtonItem4,LA_FALSE);
            laWidget_SetVisible((laWidget*)ButtonItem4,LA_FALSE);
        }
        
        count++;
        
        if ((count+page*5)< MAXITEMS)
        {
            laWidget_SetEnabled((laWidget*)ButtonItem5,LA_TRUE);
            laWidget_SetVisible((laWidget*)ButtonItem5,LA_TRUE); // See ButtonItem1
            
            laString_Initialize(&newString);

            newString = laString_CreateFromCharBuffer(ItemList[page*5+count], GFXU_StringFontIndexLookup(&stringTable,string_DummyString,0));
        
            laButtonWidget_SetText(ButtonItem5,newString);
            laString_Destroy(&newString);
        
        }
        else
        {
            laWidget_SetEnabled((laWidget*)ButtonItem5,LA_FALSE);
            laWidget_SetVisible((laWidget*)ButtonItem5,LA_FALSE);
        }
        
        if(page > 0) // Is this not the first page
        {
            laWidget_SetEnabled((laWidget*)ButtonLeft,LA_TRUE); // Enable the "Left-Button""
            laWidget_SetVisible((laWidget*)ButtonLeft,LA_TRUE); // Show this button
        }
        else
        {
            laWidget_SetEnabled((laWidget*)ButtonLeft,LA_FALSE); // Disable the "Left-Button"
            laWidget_SetVisible((laWidget*)ButtonLeft,LA_FALSE); // Hide this button
        }
        
        if ((count+page*5)< MAXITEMS) // Is this not the last page
        {
            laWidget_SetEnabled((laWidget*)ButtonRight,LA_TRUE); // Enable the "Right-Button"
            laWidget_SetVisible((laWidget*)ButtonRight,LA_TRUE); // Show this button
        }
        else
        {
            laWidget_SetEnabled((laWidget*)ButtonRight,LA_FALSE); // Disable the "Right"-button
            laWidget_SetVisible((laWidget*)ButtonRight,LA_FALSE); // Hide this button
        }
           
    }


    void APP_Tasks( void )
    {

          ...
          
          case APP_STATE_ITEMSELECT:
          {
              APP_Item_Page(ItemPage);
              laContext_SetActiveScreen(2);
              
          }
          
          
          ...

    }

     
    Workshop is MPLAB X IDE v4.15, MPLAB Harmony v2_05_01, controller
    #11
    kuku
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2012/03/03 08:05:54
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2018/03/26 10:22:36 (permalink)
    0
    I don't see in this code where you call laString_Copy(). BTW, for this function you must give parameter in laString type, I quess that you give him null pointer.
    #12
    StefanK.
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2017/10/27 04:22:35
    • Location: 0
    • Status: offline
    Re: laLabelWidget_SetText causes crash 2018/03/26 23:13:22 (permalink)
    0
    @kuku
     
    The laString_Copy function is called by the laButtonWidget_SetText(..) function in the deep of harmony source code.
    #13
    Jump to:
    © 2018 APG vNext Trial Version 4.5