Skip to content

Commit

Permalink
Improved memory handling in SortUUIDLIst
Browse files Browse the repository at this point in the history
Improved memory handling and early release of allocated resources short improve situatin for Issue #1119.
  • Loading branch information
NikkiLacrima authored Jan 24, 2025
1 parent 38503cc commit 3986edd
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/collar/oc_dialog.lsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Medea Destiny -
Nikki Lacrima
Aug 2023 - Changed functions for clearing auth so auth doesn't persist for open menus
Sep 2024 - Invalidate all menus except wearer when public or group mode is turned off
Jan 2025 - Improved memory handling in SortUUIDList, clear resources as early as possible
*/
integer CMD_ZERO = 0;
Expand Down Expand Up @@ -260,7 +261,6 @@ Dialog(key kRecipient, string sPrompt, list lMenuItems, list lUtilityButtons, in
sButton = TruncateString(sButton, 24);
if(llSubStringIndex(sButton, "secondlife://")!=-1) sButton = sButtonNumber;


lButtons = llListReplaceList(lButtons, [sButton], iCur,iCur);
}
iNBPromptlen=GetStringBytes(sNumberedButtons);
Expand Down Expand Up @@ -312,7 +312,7 @@ Dialog(key kRecipient, string sPrompt, list lMenuItems, list lUtilityButtons, in
integer iListener = llListen(iChan, "", kRecipient, "");

//send dialog to viewer
if (llGetListLength(lMenuItems+lUtilityButtons)){
if (llGetListLength(lMenuItems)+llGetListLength(lUtilityButtons)){
list lNavButtons;
if (iNumitems > iMyPageSize) lNavButtons=[PREV,MORE];
if(g_iShowLevel)sThisPrompt += "\nAuth Level: "+(string)iAuth;
Expand Down Expand Up @@ -348,8 +348,7 @@ integer IsUUIDList(list lTmp)

list SortUUIDList(list lToSort){
integer i = 0;
list lNameList = [];
list lSorted;
list lIndexNameList = [];
integer end = llGetListLength(lToSort);
for(i=0;i<end;i++){
string sButton = llList2String(lToSort,i);
Expand All @@ -360,23 +359,18 @@ list SortUUIDList(list lToSort){
sButton = llGetDisplayName(sButton)+" ("+llKey2Name(sButton)+")";
}
else sButton=llKey2Name((key)sButton);
lNameList += [llList2String(lToSort,i), sButton];
lSorted+=sButton;
lIndexNameList += [i, sButton];
}
//llSay(0, "lNameList : "+ llDumpList2String(lNameList, " - "));
lToSort= [];
lSorted = llListSort(lSorted, 1, TRUE);
i=0;
//llSay(0, "lSorted : "+ llDumpList2String(lSorted, " - "));
// llSay(0, "lIndexNameList : "+ llDumpList2String(lIndexNameList, " - "));
lIndexNameList = llListSortStrided(lIndexNameList, 2, 1, TRUE);
// llSay(0, "lIndexNameList : "+ llDumpList2String(lIndexNameList, " - "));
list lFinal;
end=llGetListLength(lSorted);
for(i=0;i<end;i++){
integer index = llListFindList(lNameList, [llList2String(lSorted,i)]);
lFinal += [llList2String(lNameList, index-1)];
lFinal += [llList2String(lToSort,llList2Integer(lIndexNameList, 2*i))];
}
//llSay(0, "lFinal : "+ llDumpList2String(lFinal, " - "));
lNameList=[];
lSorted=[];
// llSay(0, "lFinal : "+ llDumpList2String(lFinal, " - "));
lToSort = [];
lIndexNameList=[];
return lFinal;
}

Expand Down Expand Up @@ -437,7 +431,6 @@ CleanList() {
}
}


ClearUser(key kRCPT) {
//find any strides belonging to user and remove them
integer iIndex = llListFindList(g_lMenus, [kRCPT]);
Expand Down Expand Up @@ -529,7 +522,6 @@ state active
llOwnerSay("Dialog Response\n\n[iChan = "+(string)iChan+", sName = "+sName+", kID = "+(string)kID+", sMessage = "+sMessage+"]");
}


integer iMenuIndex = llListFindList(g_lMenus, [iChan]);
if (~iMenuIndex) {
key kMenuID = llList2Key(g_lMenus, iMenuIndex + 1);
Expand Down Expand Up @@ -635,8 +627,6 @@ state active
else g_bSensorLock=FALSE;
}



link_message(integer iSender, integer iNum, string sStr, key kID) {
if (iNum == SENSORDIALOG){
//first, store all incoming parameters in a global sensor details list
Expand All @@ -655,7 +645,10 @@ state active
//Debug("DIALOG:"+sStr);
string extraInfo = "";
list lParams = llParseStringKeepNulls(sStr, ["|"], []);
sStr = "";
//first clean out any strides already in place for that user. prevents having lots of listens open if someone uses the menu several times while sat
key kRCPT = llGetOwnerKey((key)llList2String(lParams, 0));
ClearUser(kRCPT);
string sPrompt = llList2String(lParams, 1);
integer iPage = (integer)llList2String(lParams, 2);
if (iPage < 0 ) {
Expand All @@ -673,12 +666,13 @@ state active
integer iSorted=FALSE;
if (llGetListLength(lParams)>=6) iAuth = llList2Integer(lParams, 5);
if (llGetListLength(lParams)>=7) iSorted = llList2Integer(lParams, 6);
//first clean out any strides already in place for that user. prevents having lots of listens open if someone uses the menu several times while sat
if (llGetListLength(lParams)>=8) extraInfo = llList2String(lParams, 7);
lParams = [];

if(iSorted && IsUUIDList(lButtons))lButtons = SortUUIDList(lButtons);
else if(iSorted && !IsUUIDList(lButtons))lButtons = llListSort(lButtons, 1, TRUE);

if (llGetListLength(lParams)>=8) extraInfo = llList2String(lParams, 7);
ClearUser(kRCPT);
llSleep(0.01); /* make sure that we are on the next server frame */
Dialog(kRCPT, sPrompt, lButtons, ubuttons, iPage, kID, iDigits, iAuth,extraInfo, iSorted);
}

Expand Down Expand Up @@ -753,7 +747,6 @@ state active
}

state_entry(){

g_kWearer=llGetOwner();
g_sPrefix = llToLower(llGetSubString(llKey2Name(llGetOwner()), 0,1));
g_sWearerName = NameURI(g_kWearer);
Expand Down Expand Up @@ -792,4 +785,3 @@ state inUpdate{
}
}
}

0 comments on commit 3986edd

Please sign in to comment.