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

9 Replies Related Threads

    Ed@Microchip
    Junior Member
    • Total Posts : 41
    • 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 : 41
    • 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 : 41
    • 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 : 41
    • 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 : 66
    • 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 : 41
    • 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 : 66
    • 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 : 66
    • 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
    Jump to:
    © 2018 APG vNext Commercial Version 4.5