Home AMX User Forum AMX General Discussion

Another Bug?

In the following code I create a stack var structure to clear my global working structure before the next go around. It's not really necessary since I'm writing new values to every element but for some reason I added it. When this code runs the structure clears and then I populate the values but when a function called directly after runs it receives a UI_Indx of 0 from this code block and that value of UI_indx coming into this code is definitely set.

The section of code:
DEFINE_FUNCTION fnFavIcon_SetResource(INTEGER iUI_Indx,INTEGER iUser,INTEGER iFav,CHAR iProtocol_Path[])
     {
     if(sFavIcon.nInitializing != FAVICON_INIT_EXIT)
	  {
	  STACK_VAR _sSent sClearSent;
	  
	  fnFavIcon_DeBug("'fnFavIcon_SetResource(), UI-[ ', itoa(iUI_Indx),' ], USER-[ ',itoa(iUser),' ], FAV-[ ',itoa(iFav),' ], INIT STATE-[ ',itoa(sFavIcon.nInitializing),' ] :DEBUG<',ITOA(__LINE__),'>'");
	  
	  if(sFavIcon.nInitializing != FAVICON_INIT_RUN)
	       {
	       sFavIcon.nInitializing = FAVICON_INIT_RUN;
	       fnFavIcon_FB_INIT(iUI_Indx);
	       }
	  sFavIcon.sSentUI = sClearSent;
	  sFavIcon.sSentUI.cResource = "'FavIcon U',itoa(iUser),' F',itoa(iFav)";
	  sFavIcon.sSentUI.nUI_Indx = iUI_Indx;
	  sFavIcon.sSentUI.nUser = iUser;
	  sFavIcon.sSentUI.nFav = iFav;
	  sFavIcon.sSentUI.nChnlIndx = sFavIcon.sUser[iUser].nCableChnlIndx[iFav];
	  sFavIcon.sSentUI.nChnl = sCableChnl[sFavIcon.sSentUI.nChnlIndx].nChnl;
	  sFavIcon.sUser[iUser].cResource[iFav] = sFavIcon.sSentUI.cResource;
	  
	  if(find_string(sCableChnl[sFavIcon.sSentUI.nChnlIndx].cIcon,"'.png'",1) || find_string(sCableChnl[sFavIcon.sSentUI.nChnlIndx].cIcon,"'.jpg'",1))
	       {
	       fnFavIcon_DoSend_UI_CMD(iUI_Indx,"'^RAF-',sFavIcon.sSentUI.cResource,iProtocol_Path,sCableChnl[sFavIcon.sUser[iUser].nCableChnlIndx[iFav]].cIcon,'%R0'");
	       fnFavIcon_DoSend_UI_CMD(iUI_Indx,"'^RFRP-',sFavIcon.sSentUI.cResource,',once'");
	       }
	  else
	       {
	       fnFavIcon_DeBug("'fnFavIcon_SetResource(), UI-[ ', itoa(iUI_Indx),' ], USER-[ ',itoa(iUser),' ], FAV-[ ',itoa(iFav),' ], ERROR SUPPORTED FILE TYPE FOUND! :DEBUG<',ITOA(__LINE__),'>'");
	       fnFavIcon_DeBug("'fnFavIcon_SetResource(), ERROR ### UI-[ ',itoa(sFavIcon.sSentUI.nUI_Indx),' ], CHECK RESOURCE ICON-[ ',sCableChnl[sFavIcon.sSentUI.nChnlIndx].cIcon,' ] ### :DEBUG<',ITOA(__LINE__),'>'");
	       fnFavIcon_DeBug("'fnFavIcon_SetResource(), ERROR ### UI-[ ',itoa(sFavIcon.sSentUI.nUI_Indx),' ], CHECK RESOURCE CABLE CHNL-[ ',itoa(sCableChnl[sFavIcon.sSentUI.nChnlIndx].nChnl),' ] ### :DEBUG<',ITOA(__LINE__),'>'");
	       fnFavIcon_Init_UIs(sFavIcon.sSentUI.nUI_Indx,sFavIcon.sSentUI.cResource);//continue to th next
	       }

My diagnostic printout:
Line    358 (19:41:48)::  FAVICON-[ * ] DEBUG:[ L1 ], fnFavIcon_Init_UIs(), UI-[ 3 ], USER-[ 4 ], FAV-[ 6 ], RCV'D RESOURCE-[ FavIcon U4 F6 ] :DEBUG<740>
Line    359 (19:41:48)::  FAVICON-[ * ] DEBUG:[ L1 ], fnFavIcon_SetResource(), UI-[ 3 ], USER-[ 4 ], FAV-[ 5 ], INIT STATE-[ 2 ] :DEBUG<950>
Line    360 (19:41:48)::  FAVICON-[ * ] DEBUG:[ L1 ], fnFB_DoSend_UI_CMD(), UI-[ 0 ], Cmd-[ ^RAF-FavIcon U4 F5,%P1%Uxxxxxxxx%Syyyyyyyyyy%H192.168.1.60%Aimages/tv_icons%Fabc_hd.png%R0 ]  :DEBUG<418>
Line    361 (19:41:48)::  FAVICON-[ * ] DEBUG:[ L1 ], fnFB_DoSend_UI_CMD(), UI-[ 0 ], Cmd-[ ^RFRP-FavIcon U4 F5,once ]  :DEBUG<418>
From this you can see the function fnFavIcon_SetResource() receives a UI_Indx value of 3 but then passes a value of 0 to fnFavIcon_DoSend_UI_CMD().

If I take out this line:
sFavIcon.sSentUI = sClearSent;
everything works fine. They are both structure type _sSent so sClearSent should clear sFavIcon.sSentUI with no problems and it does but for some odd reason populating sFavIcon.sSentUI.nUI_Indx = iUI_Indx directly after the value doesn't stick and by the micro second it takes to call and pass that value to the next function the value is gone or was simply never written.

Again I don't need this and it's probably left over from when I was only updating a couple of values here, not everything but it should still work regardless of the fact that I don't need it. Fortunately I don't so it's an easy fix but why?

Take out this:
STACK_VAR _sSent sClearSent;
sFavIcon.sSentUI = sClearSent;
and everything works but leave it in and the iUI_Indx value passed to the subsequent functions is 0 when a value other than 0 comes in.

This had me stumped for a long time since this shouldn't be a problem. Anybody seen similar anomalies?

Master is running v4.1.373

Comments

  • a_riot42a_riot42 Posts: 1,624
    You don't have your structures listed, but I would guess that you have nested structures going on. I would recommend not using nested structures unless they are very small with a small memory footprint. I've noticed that processing nested structures is very slow, and this might be a side effect of that.
    Paul
  • viningvining Posts: 4,368
    Here's the structure definitions:
    DEFINE_TYPE     //STRUCTURE _sInit
    
    STRUCTURE _sUI_Init 
         
         {
         INTEGER nLoaded;
         INTEGER nErrors;
         INTEGER nPending;
         INTEGER nForce;
         INTEGER nDelay;
         INTEGER nCount;
         }     
    
    DEFINE_TYPE 	//STRUCTURE _sSent 
    
    STRUCTURE _sSent 
         
         {
         CHAR cResource[FAVICON_LEN_RESOURCE];
         INTEGER nUI_Indx;
         INTEGER nUser;
         INTEGER nFav;
         INTEGER nChnl;
         INTEGER nChnlIndx;
         }
         
    DEFINE_TYPE 	//STRUCTURE _sUser
    
    STRUCTURE _sUser 
         
         {
         CHAR cResource[FAVICON_NUM_FAVS_EACH][FAVICON_LEN_RESOURCE];
         INTEGER nCableChnlIndx[FAVICON_NUM_FAVS_EACH];
         INTEGER nLoaded;
         }
         
    DEFINE_TYPE 	//STRUCTURE _sFavIcon 
    
    STRUCTURE _sFavIcon 
         
         {
         INTEGER nUI_OnPage[NUM_UIs_IN_SYSTEM];
         INTEGER nUI_User[NUM_UIs_IN_SYSTEM];
         INTEGER nUI_FavType[NUM_UIs_IN_SYSTEM];
         INTEGER nInitializing;
         INTEGER nUI_Init_Pending;
         CHAR cProtocolHostPath[FAVICON_LEN_PROTOPATH];
         CHAR cUserPass[FAVICON_LEN_USERPASS];
         CHAR cProtocol[1];
         _sSent sSentUI;
         _sSent sSentUser;
         _sUser sUser[FAVICON_NUM_USERS];
         _sUI_Init sUI_Init[NUM_UIs_IN_SYSTEM];
         }
         
    DEFINE_TYPE 	//STRUCTURE _sChnls 
    
    STRUCTURE _sCableChnl 
         
         {
         CHAR cName[FAVICON_LEN_CHNLNAME];
         INTEGER nChnl;
         CHAR cIcon[FAVICON_LEN_ICONNAME];
         INTEGER nIsHD;
         }
     
    DEFINE_VARIABLE //STRUCTURE VARS
    
    VOLATILE _sFavIcon sFavIcon;
    VOLATILE _sCableChnl sCableChnl[FAVICON_TOTAL_CHNLS];
    
    So while the problem does deal with a nested structure it's only one level deep and it has only 5 integer and 1 string. The entire structure itself is relatively small too. When I encountered this issue I only had 4 users w/ 6 favorites each declared just to expedite testing while updating all 6 declared UIs with the send commands to update all 6 UIs * 4 users * 6 favorite resources (dynamic image) each.
    VOLATILE INTEGER FAVICON_NUM_USERS	= 4;//8
    VOLATILE INTEGER FAVICON_NUM_FAVS_EACH	= 6;//16
    VOLATILE INTEGER FAVICON_LEN_ICONNAME	= 64;
    VOLATILE INTEGER FAVICON_LEN_CHNLNAME	= 64;
    VOLATILE INTEGER FAVICON_LEN_RESOURCE	= 64;
    VOLATILE INTEGER FAVICON_LEN_PROTOPATH	= 128;//PROTOCOL & PATH
    VOLATILE INTEGER FAVICON_TOTAL_ICONS	= 64;
    VOLATILE INTEGER FAVICON_TOTAL_CHNLS	= 32;//use low number for testing
    
    And while there's definitely an issue I don't see how the processor handling nested structures slowly could be the issue. Since the processor is single threaded it has to finish updating that branch of the structure before continuing to following code that re-populates it value. And the weird thing is it only seemed to affect the UI_Indx var and not the others that were also updated there after. I think I might have to step through the code to see if I can get a better indication of where this breaks.
Sign In or Register to comment.