Foreach multi-iterator problem
#1

Hello! I make a inventory system using a multi-iterator system for items per-players. But my problem is that server is crashing, when i use a Iter_SafeRemove in foreach loop and after this again loop in other function. This is:

Код:
foreach(new itemid : PlayerItem[playerid])
{
	if(PlayerItemCache[playerid][itemid][iUID])
	{
 		UnloadPlayerItem(playerid, itemid);
		Iter_SafeRemove(PlayerItem[playerid], itemid, next_player_item);

		itemid = next_player_item;
	}
}

public UnloadPlayerItem(playerid, itemid)
{
	for(new sPlayerItem:e; e < sPlayerItem; ++e)	PlayerItemCache[playerid][itemid][e] = 0;
	orm_destroy(PlayerItemCache[playerid][itemid][iOrm]);
	return 1;
}


public ListPlayerItems(playerid)
{
	new list_items[2048], item_count = Iter_Count(PlayerItem[playerid]), item_weight, item_weight_sum;
	format(list_items, sizeof(list_items), "UID\tNazwa przedmiotu\tWaga\n \t» Funkcja zaznaczania\n \t» Przedmioty w pobliżu\n---\n");

	foreach(new itemid : PlayerItem[playerid])
	{
	    if(PlayerItemCache[playerid][itemid][iUID])
	    {
	    	item_weight = GetPlayerItemWeight(playerid, itemid);
	    	if(PlayerItemCache[playerid][itemid][iUsed])
	    	{
				format(list_items, sizeof(list_items), "%s\n{FFFFFF}%d\t{C0C0C0}%s\t%dg", list_items, PlayerItemCache[playerid][itemid][iUID], PlayerItemCache[playerid][itemid][iName], item_weight);
			}
			else
			{
   			 	format(list_items, sizeof(list_items), "%s\n{C0C0C0}%d\t{C0C0C0}%s\t%dg", list_items, PlayerItemCache[playerid][itemid][iUID], PlayerItemCache[playerid][itemid][iName], item_weight);
			}

			item_weight_sum += item_weight;
  		}
	}

	if(item_count > 0)
	{
		new title[256];

		format(title, sizeof(title), "Lista Twoich przedmiotуw [ilość: %d | suma wag: %dg]", item_count, item_weight_sum);
		ShowPlayerDialog(playerid, D_ITEM_USE, DIALOG_STYLE_TABLIST_HEADERS, title, list_items, "Użyj", "Opcje...");
	}
	else
	{
        TD_ShowSmallInfo(playerid, 5, "Nie posiadasz ~r~zadnych ~w~przedmiotow w ekwipunku.");
	}
	return 1;
}
Just somebody know, that's why my server is crashing when after deleting loop i use a ListPlayerItems? That is'nt bug in y_iterator?
Reply
#2

How server crashes? Please show us crashdetect logs.
Reply
#3

crashdetect shows nothing. server just stop working.
Reply
#4

Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[11:00:46] 
[11:00:46] Server Plugins
[11:00:46] --------------
[11:00:46]  Loading plugin: crashdetect.so
[11:00:46]   CrashDetect v4.15.1 is OK.
[11:00:46]   Loaded.
[11:00:46]  Loading plugin: streamer.so
[11:00:46] 

*** Streamer Plugin v2.8.2 by Incognito loaded ***

[11:00:46]   Loaded.
[11:00:46]  Loading plugin: mysql_static.so
[11:00:47]  >> plugin.mysql: R39-5 successfully loaded.
[11:00:47]   Loaded.
[11:00:47]  Loaded 3 plugins.

[11:00:50] 
[11:00:50] Filterscripts
[11:00:50] ---------------
[11:00:50]   Loaded 0 filterscripts.

[11:00:50]  
[11:00:50]  
[11:00:50]  
[11:00:50]  ======================================= 
[11:00:50]  |                                     | 
[11:00:50]  |        YSI version 4.00.0001        | 
[11:00:50]  |        By Alex "******" Cole        | 
[11:00:50]  |                                     | 
[11:00:50]  ======================================= 
[11:00:50]  
[11:00:50] 
----------------------------------
[11:00:50]  Blank Gamemode by your name here
[11:00:50] ----------------------------------

[11:00:50] Number of vehicle models: 0
[11:02:37] [connection] 31.178.243.197:57064 requests connection cookie.
[11:02:37] [connection] incoming connection: 31.178.243.197:57064 id: 0
[11:02:39] [join] Mario has joined the server (0:31.178.243.197)
[11:02:59] [chat] [Mario]: test!!!!!
[11:03:28] [chat] [Mario]: test!!!!
Before text "test" i use a foreach with saferemove after this i using a ListPlayerItems. In the first case it works good, because after second text server i crash.
Reply
#5

There is why i need to fix it. I've got item checking in inventory system and doing a lot of actions in one loop and one dialog. After i do the action checking and droping items at ground and using ListPlayerItems after this, server is crash.

Код:
	if(dialogid == D_ITEM_CHECK)
	{
	    if(response)
    	{
    	    if(PlayerCache[playerid][pPuttingBag])
    	    {
    	        new bag_item_id = PlayerCache[playerid][pItemArray][ITEM_BAG] = GetPlayerItemID(playerid, strval(inputtext));

				if(!Iter_Contains(PlayerItem[playerid], bag_item_id))
    	        {
    	            return 1;
				}
				
				if(PlayerItemCache[playerid][bag_item_id][iType] != ITEM_BAG)
				{
				    return 1;
				}
    	        
    	        listitem = 2;
				goto putting_bag;
				
				return 1;
    	    }
    	
    	    if(listitem == 0)
    	    {
    	        CallLocalFunction("ListPlayerCheckedItems", "d", playerid);
    	        return 1;
    	    }
	    
	        if(listitem <= 5)
	        {
	            new checked_items, last_itemid = INVALID_ITEM_ID;
	            foreach(new itemid : PlayerItem[playerid])
	            {
	                if(PlayerItemCache[playerid][itemid][iChecked])
	                {
	                    checked_items ++;
	                    
	                    // ŁĄCZENIE PRZEDMIOTУW
	                    if(listitem == 5)
	                    {
							if(last_itemid != INVALID_ITEM_ID)
       						{
								if(PlayerItemCache[playerid][itemid][iType] != PlayerItemCache[playerid][last_itemid][iType] || PlayerItemCache[playerid][itemid][iValue][1] != PlayerItemCache[playerid][last_itemid][iValue][1])
								{
								    CallLocalFunction("ListPlayerCheckedItems", "d", playerid);
				    				TD_ShowSmallInfo(playerid, 5, "Do ~y~polaczenia ~w~przedmiotow musisz ~g~zaznaczyc ~w~tylko tego samego typu.");
								    return 1;
								}
							}
							last_itemid = itemid;
	                    }
	                }
	            }
	            
	            if(checked_items < 2)
	            {
	                CallLocalFunction("ListPlayerCheckedItems", "d", playerid);
	                TD_ShowSmallInfo(playerid, 5, "Musisz ~g~zaznaczyc ~w~przynajmniej ~y~dwa ~w~przedmioty, by nimi manipulowac.");
	                return 1;
	            }
	            
	            if(listitem == 5)
	            {
	                if(PlayerItemCache[playerid][last_itemid][iType] != ITEM_CIGGY && PlayerItemCache[playerid][last_itemid][iType] != ITEM_DRUG)
	                {
	                    ListPlayerCheckedItems(playerid);
	                    TD_ShowSmallInfo(playerid, 5, "Nie mozesz ~y~polaczyc ~w~ze soba tego typu przedmiotow.");
	                    return 1;
	                }
	            }
	        
				new main_query[2048], query[128], string_lenght, next_player_item, bag_item_id,
     				Float:PosX, Float:PosY, Float:PosZ, Float:PosA, virtual_world, interior_id;
					
				new items_list_info[512];
				
				switch(listitem)
				{
				    case 1:
				    {
				        if(IsPlayerInAnyVehicle(playerid))
				        {
				            new vehid = GetVehicleIndex(GetPlayerVehicleID(playerid)), veh_uid = VehicleCache[vehid][vUID];
				            ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.1, 0, 0, 0, 0, 0, 1);
				            
							format(main_query, sizeof(main_query), "UPDATE `myrp_items` SET item_place = '%d', item_owner = '%d' WHERE ", PLACE_VEHICLE, veh_uid);
							format(items_list_info, sizeof(items_list_info), "Przedmioty odłożone w pojeździe %s (UID: %d):\n", GetVehicleName(VehicleCache[vehid][vModel]), veh_uid);
				        }
				        else
				        {
	  						GetPlayerPos(playerid, PosX, PosY, PosZ);
							GetPlayerFacingAngle(playerid, PosA);

							virtual_world = GetPlayerVirtualWorld(playerid);
							interior_id = GetPlayerInterior(playerid);

					        ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.1, 0, 0, 0, 0, 0, 1);

							format(main_query, sizeof(main_query), "UPDATE `myrp_items` SET item_place = '%d', item_owner = '0', item_posx = '%f', item_posy = '%f', item_posz = '%f', item_world = '%d', item_interior = '%d' WHERE ", PLACE_NONE, PosX, PosY, PosZ, virtual_world, interior_id);
	                        format(items_list_info, sizeof(items_list_info), "Przedmioty zostały odłożone w pobliżu:\n");
						}
					}
					case 2:
					{
					    if(!PlayerCache[playerid][pPuttingBag])
					    {
	  						new list_bags[512] = "Identyfikator\tNazwa przedmiotu", item_count;
							foreach(new i : PlayerItem[playerid])
							{
							    if(PlayerItemCache[playerid][i][iType] == ITEM_BAG)
							    {
							        item_count ++;
							        format(list_bags, sizeof(list_bags), "%s\n%d\t%s", list_bags, PlayerItemCache[playerid][i][iUID], PlayerItemCache[playerid][i][iName]);
							    }
							}

							if(item_count > 0)
							{
							    ShowPlayerDialog(playerid, D_ITEM_CHECK, DIALOG_STYLE_TABLIST_HEADERS, "Włуż do przedmiotu:", list_bags, "Włуż", "Wrуć");
								PlayerCache[playerid][pPuttingBag] = true;
							}
							else
							{
							    TD_ShowSmallInfo(playerid, 5, "Nie posiadasz ~r~zadnych ~w~przedmiotow do ktorych mozna cos wlozyc.");
							}
							return 1;
						}
						
						putting_bag:
						bag_item_id = PlayerCache[playerid][pItemArray][ITEM_BAG];

						format(main_query, sizeof(main_query), "UPDATE `myrp_items` SET item_place = '%d', item_owner = '%d' WHERE ", PLACE_BAG, PlayerItemCache[playerid][bag_item_id][iUID]);
                        format(items_list_info, sizeof(items_list_info), "Przedmioty zostały włożone do przedmiotu %s (UID: %d):\n", PlayerItemCache[playerid][bag_item_id][iName], PlayerItemCache[playerid][bag_item_id][iUID]);
                        
						PlayerCache[playerid][pPuttingBag] = false;
					}
					case 5:
					{
					    new item_name[32];
					    strmid(item_name, PlayerItemCache[playerid][last_itemid][iName], 0, 32, 32);
					    
					    format(main_query, sizeof(main_query), "DELETE FROM `myrp_items` WHERE ");
					    last_itemid = CreatePlayerItem(playerid, item_name, PlayerItemCache[playerid][last_itemid][iType], 0, PlayerItemCache[playerid][last_itemid][iValue][1]);

                    	format(items_list_info, sizeof(items_list_info), "Przedmioty zostały połączone tworząc %s (UID: %d):\n", PlayerItemCache[playerid][last_itemid][iName], PlayerItemCache[playerid][last_itemid][iUID]);
					}
				}
	            string_lenght = strlen(main_query);
	            
	            new object_id;
	            foreach(new itemid : PlayerItem[playerid])
	            {
	                if(PlayerItemCache[playerid][itemid][iChecked])
	                {
	                    format(query, sizeof(query), "item_uid = %d", PlayerItemCache[playerid][itemid][iUID]);
						if(strlen(main_query) > string_lenght)
						{
							if(strlen(main_query) + strlen(query) < sizeof(main_query))
   				    		{
				   				strcat(main_query, " OR ", sizeof(main_query));
							}
							else
							{
					    		strcat(main_query, ";", sizeof(main_query));
					    		mysql_query(MysqlHandle, main_query);

					    		strdel(main_query, string_lenght, strlen(main_query));
							}
						}
						strcat(main_query, query, sizeof(main_query));
						
						if(listitem == 1)
						{
						    if(!IsPlayerInAnyVehicle(playerid))
						    {
    							object_id = CreateDynamicObject(2843, PosX + random(2), PosY - random(2), PosZ - 1.0, 0.0, 0.0, -PosA, virtual_world, -1, -1);

								Streamer_SetIntData(STREAMER_TYPE_OBJECT, object_id, E_STREAMER_EXTRA_ID, (PlayerItemCache[playerid][itemid][iUID] * -1));
								Streamer_UpdateEx(playerid, PosX, PosY, PosZ, virtual_world, interior_id, STREAMER_TYPE_OBJECT);
							}
						}
						
						if(listitem == 2)
						{
						    PlayerItemCache[playerid][bag_item_id][iValue][0] += GetPlayerItemWeight(playerid, itemid);
						}
						
						if(listitem == 5)
						{
						    PlayerItemCache[playerid][last_itemid][iValue][0] += PlayerItemCache[playerid][itemid][iValue][0];
						}
						
						format(items_list_info, sizeof(items_list_info), "%s\n• %s (%d)", items_list_info, PlayerItemCache[playerid][itemid][iName], PlayerItemCache[playerid][itemid][iUID]);

                        UnloadPlayerItem(playerid, itemid);
						Iter_SafeRemove(PlayerItem[playerid], itemid, next_player_item);
						
						itemid = next_player_item;
	                }
	            }
	            
	            if(listitem == 2)
	            {
	                orm_update(PlayerItemCache[playerid][bag_item_id][iOrm]);
	            }
	            
	            if(listitem == 5)
	            {
	                orm_update(PlayerItemCache[playerid][last_itemid][iOrm]);
	            }
	            
	            mysql_query(MysqlHandle, main_query);
	            ShowPlayerDialog(playerid, D_NONE, DIALOG_STYLE_MSGBOX, "Informacja", items_list_info, "OK", "");
	            return 1;
	        }
	    
			new item_uid = strval(inputtext),
				itemid = GetPlayerItemID(playerid, item_uid);
			
			if(PlayerItemCache[playerid][itemid][iChecked])
			{
				PlayerItemCache[playerid][itemid][iChecked] = false;
				TD_ShowSmallInfo(playerid, 3, "Przedmiot zostal ~r~odznaczony~w~.");
			}
			else
			{
				PlayerItemCache[playerid][itemid][iChecked] = true;
				TD_ShowSmallInfo(playerid, 3, "Przedmiot zostal ~g~zaznaczony~w~.");
			}
			CallLocalFunction("ListPlayerCheckedItems", "d", playerid);
	        return 1;
	    }
	    else
	    {
	        new callback[128];
	        if(PlayerCache[playerid][pPuttingBag])
	        {
	        	PlayerCache[playerid][pPuttingBag] = false;
	        	callback = "ListPlayerCheckedItems";
			}
	        else
			{
       			callback = "ListPlayerItems";
			}
			CallLocalFunction(callback, "d", playerid);
	        return 1;
	    }
	}
I think that is can be a bug in y_iterator with multi-iterations.
Reply
#6

pawn Код:
#include <a_samp>
#define _inc_a_samp
#include <YSI\y_iterate>

main () {
}

new Iterator:Vector[2]<5>;

public OnGameModeInit()
{
    Iter_Add(Vector[0], 0);
    Iter_Add(Vector[0], 1);
    Iter_Add(Vector[0], 2);
    Iter_Add(Vector[0], 3);
    Iter_Add(Vector[0], 4);

    foreach(new i : Vector[0])
    {
        if(i == 2)
        {
            Iter_SafeRemove(Vector[0], i, i);
        }
    }


    foreach(new i : Vector[0])
    {
        printf("%d", i);
    }

    return 1;
}
Cannot reproduce, therefore it's unlikely it's an YSI bug.

I suspect infinite loop, not a crash. Put printf("%d", itemid) inside your loop in ListPlayerItems, we'll see if that's the case.
Reply
#7

Код:
public ListPlayerItems(playerid)
{
	new list_items[2048], item_count = Iter_Count(PlayerItem[playerid]), item_weight, item_weight_sum;
	format(list_items, sizeof(list_items), "UID\tNazwa przedmiotu\tWaga\n \t» Funkcja zaznaczania\n \t» Przedmioty w pobliżu\n---\n");
	
	printf("ListPlayerItems[1]");
	foreach(new itemid : PlayerItem[playerid])
	{
	    printf("ListPlayerItems[2]: %d", itemid);
	    if(PlayerItemCache[playerid][itemid][iUID])
	    {
	        printf("ListPlayerItems[3]: %d", itemid);
	    	item_weight = GetPlayerItemWeight(playerid, itemid);
	    	if(PlayerItemCache[playerid][itemid][iUsed])
	    	{
				format(list_items, sizeof(list_items), "%s\n{FFFFFF}%d\t{C0C0C0}%s\t%dg", list_items, PlayerItemCache[playerid][itemid][iUID], PlayerItemCache[playerid][itemid][iName], item_weight);
			}
			else
			{
   			 	format(list_items, sizeof(list_items), "%s\n{C0C0C0}%d\t{C0C0C0}%s\t%dg", list_items, PlayerItemCache[playerid][itemid][iUID], PlayerItemCache[playerid][itemid][iName], item_weight);
			}

			item_weight_sum += item_weight;
			printf("ListPlayerItems[4]: %d", itemid);
  		}
	}

	printf("ListPlayerItems[5]");
	if(item_count > 0)
	{
		new title[256];
		
		format(title, sizeof(title), "Lista Twoich przedmiotуw [ilość: %d | suma wag: %dg]", item_count, item_weight_sum);
		ShowPlayerDialog(playerid, D_ITEM_USE, DIALOG_STYLE_TABLIST_HEADERS, title, list_items, "Użyj", "Opcje...");
	}
	else
	{
        TD_ShowSmallInfo(playerid, 5, "Nie posiadasz ~r~zadnych ~w~przedmiotow w ekwipunku.");
	}
	printf("ListPlayerItems[6]");
	return 1;
}
ServerLog:

Код:
[12:25:19] ListPlayerItems[1]
[12:25:19] ListPlayerItems[2]: 0
[12:25:19] ListPlayerItems[3]: 0
[12:25:19] ListPlayerItems[4]: 0
[12:25:19] ListPlayerItems[2]: 1
[12:25:19] ListPlayerItems[3]: 1
[12:25:19] ListPlayerItems[4]: 1
[12:25:19] ListPlayerItems[2]: 2
[12:25:19] ListPlayerItems[3]: 2
[12:25:19] ListPlayerItems[4]: 2
[12:25:19] ListPlayerItems[2]: 5
[12:25:19] ListPlayerItems[2]: 8
[12:25:19] ListPlayerItems[2]: 11
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
[12:25:19] ListPlayerItems[2]: 14
Looks like infinite looping. But why?

That's all is after using iter_saferemove of course in checking items.
Reply
#8

There's nothing wrong with the code (only eyesore goto's and unthreaded queries ).
Last try at debugging:
1) Write down exactly how many slots the iterator has (just paste the declaration and used constants/definitions - in case you use them)
2) Add another loop right before the one with SafeRemove, and print out all taken slots
3) Paste how far the infinite loop gets to.

Oh, and are you using YSI 3 or 4?
Reply
#9

YSI version 4.00.0001

Код:

#define MAX_PLAYERS          	10
#define MAX_ITEM_CACHE  		75

new Iterator:PlayerItem[MAX_PLAYERS]<MAX_ITEM_CACHE>;
Код:
	if (strcmp("/test", cmdtext, true, 10) == 0)
	{
	    foreach(new itemid : PlayerItem[playerid])
	    {
	        printf("ITEMID: %d", itemid);
	    }
	    return 1;
	}
Before using saferemove, command /test:

Код:
[13:36:16] ITEMID: 0
[13:36:16] ITEMID: 1
[13:36:16] ITEMID: 2
[13:36:16] ITEMID: 3
[13:36:16] ITEMID: 4
[13:36:16] ITEMID: 5
[13:36:16] ITEMID: 6
[13:36:16] ITEMID: 7
[13:36:16] ITEMID: 8
[13:36:16] ITEMID: 9
[13:36:16] ITEMID: 10
[13:36:16] ITEMID: 11
[13:36:16] ITEMID: 12
[13:36:16] ITEMID: 13
[13:36:16] ITEMID: 14
[13:36:16] ITEMID: 15
[13:36:16] ITEMID: 16
[13:36:16] ITEMID: 17
[13:36:16] ITEMID: 18
[13:36:16] ITEMID: 19
[13:36:16] ITEMID: 20
[13:36:16] ITEMID: 21
[13:36:16] ITEMID: 22
[13:36:16] ITEMID: 23
[13:36:16] ITEMID: 24
[13:36:16] ITEMID: 25
[13:36:16] ITEMID: 26
[13:36:16] ITEMID: 27
[13:36:16] ITEMID: 28
[13:36:16] ITEMID: 29
[13:36:16] ITEMID: 30
[13:36:16] ITEMID: 31
[13:36:16] ITEMID: 32
[13:36:16] ITEMID: 33
What itemid i will removed in checking items:

Код:
[13:37:20] Iter_SafeRemove(PlayerItem[playerid], 6);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 7);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 8);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 9);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 10);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 11);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 12);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 13);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 14);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 15);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 30);
[13:37:21] Iter_SafeRemove(PlayerItem[playerid], 31);
What /test return after removing:

Код:
[13:37:47] ITEMID: 0
[13:37:47] ITEMID: 1
[13:37:47] ITEMID: 2
[13:37:47] ITEMID: 3
[13:37:47] ITEMID: 4
[13:37:47] ITEMID: 5
[13:37:47] ITEMID: 8
[13:37:47] ITEMID: 11
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:47] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
[13:37:48] ITEMID: 14
infinite loop.

EDIT:// The ITEMID 11 wasn't removed, or what?
Reply
#10

Items 8, 11 and 14 aren't removed at all it seems - and I have no clue as to why. Heap corruption? Create a new .pwn file
pawn Код:
#include <a_samp>
#define _inc_a_samp

#undef MAX_PLAYERS
#define MAX_PLAYERS             10

#include <YSI\y_iterate>

#define MAX_ITEM_CACHE          75

new Iterator:PlayerItem[MAX_PLAYERS]<MAX_ITEM_CACHE>;

main () {
}

public OnGameModeInit()
{
    for (new i = 0; i != 34; ++i) {
        Iter_Add(PlayerItem[0], i);
    }

    Iter_Remove(PlayerItem[0], 6);
    Iter_Remove(PlayerItem[0], 7);
    Iter_Remove(PlayerItem[0], 8);
    Iter_Remove(PlayerItem[0], 9);
    Iter_Remove(PlayerItem[0], 10);
    Iter_Remove(PlayerItem[0], 11);
    Iter_Remove(PlayerItem[0], 12);
    Iter_Remove(PlayerItem[0], 13);
    Iter_Remove(PlayerItem[0], 14);
    Iter_Remove(PlayerItem[0], 15);
    Iter_Remove(PlayerItem[0], 30);
    Iter_Remove(PlayerItem[0], 31);

    foreach(new i : PlayerItem[0])
    {
        printf("%d", i);
    }

    return 1;
}
(Iter_Remove uses same mechanism as Iter_SafeRemove)

Run it and see if it works. If it works correctly, then the issue is with your code, otherwise I'll have to dig deeper.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)