Foreach saferemove causes infinite loop
#1

Hey

Im using foreach 19 (0.4.3) and removing iterators from loop causes crash.

i followed the instuctions asthis topic says but the problem is still alive and sometimes this function causes this error too:

Код HTML:
[2017/10/01 16:22:20] [debug] Run time error 4: "Array index out of bounds"
[2017/10/01 16:22:20] [debug]  Accessing element at index 1000 past array upper bound 999
and this is my code:

Код HTML:
	foreach(new serveritemid : ServerItems)
	{
		count[serveritemid]++;
		if(count[serveritemid] == 3)
		{
			new Prev = Iter_Prev(ServerItems, serveritemid);
			printf("remove %d || Prev: %d", serveritemid, Prev);
			Iter_SafeRemove(ServerItems, serveritemid, Prev);
		}
		if(!Iter_Count(ServerItems))
		{
			printf("ServerItems empty");
		}
		printf("%d", serveritemid);
	}
output:
Код HTML:
[2017/10/01 17:19:30] 0
[2017/10/01 17:19:30] 1
[2017/10/01 17:19:30] 2
[2017/10/01 17:19:30] 3
[2017/10/01 17:19:30] 4
[2017/10/01 17:19:30] 5
[2017/10/01 17:19:30] 6
[2017/10/01 17:19:32] 0
[2017/10/01 17:19:32] 1
[2017/10/01 17:19:32] 2
[2017/10/01 17:19:32] 3
[2017/10/01 17:19:32] 4
[2017/10/01 17:19:32] 5
[2017/10/01 17:19:32] 6
[2017/10/01 17:19:34] remove 0 || Prev: 1000
[2017/10/01 17:19:34] 0
[2017/10/01 17:19:34] 0
[2017/10/01 17:19:34] 0
[2017/10/01 17:19:34] 0
[2017/10/01 17:19:34] 0
how could be the next id the array's max size?

Код HTML:
	foreach(new serveritemid : ServerItems)
	{
		count[serveritemid]++;
		if(count[serveritemid] == 3)
		{
			new next = Iter_Next(ServerItems, serveritemid);
			printf("remove %d || next: %d", serveritemid, next);
			Iter_SafeRemove(ServerItems, serveritemid, next);
		}
		if(!Iter_Count(ServerItems))
		{
			printf("ServerItems empty");
		}
		printf("%d", serveritemid);
	}
output

Код HTML:
[2017/10/01 17:17:15] 0
[2017/10/01 17:17:15] 1
[2017/10/01 17:17:15] 2
[2017/10/01 17:17:15] 3
[2017/10/01 17:17:15] 4
[2017/10/01 17:17:15] 5
[2017/10/01 17:17:15] 6
[2017/10/01 17:17:17] 0
[2017/10/01 17:17:17] 1
[2017/10/01 17:17:17] 2
[2017/10/01 17:17:17] 3
[2017/10/01 17:17:17] 4
[2017/10/01 17:17:17] 5
[2017/10/01 17:17:17] 6
[2017/10/01 17:17:19] remove 0 || next: 1
[2017/10/01 17:17:19] 0
[2017/10/01 17:17:19] 0
[2017/10/01 17:17:19] 0

thanks for your help
Reply


Messages In This Thread
Foreach saferemove causes infinite loop - by m4karow - 01.10.2017, 14:27
Re: Foreach saferemove causes infinite loop - by m4karow - 01.10.2017, 16:22
Re: Foreach saferemove causes infinite loop - by raydx - 01.10.2017, 17:18
Re: Foreach saferemove causes infinite loop - by m4karow - 01.10.2017, 17:32
Re: Foreach saferemove causes infinite loop - by Marricio - 01.10.2017, 18:45
Re: Foreach saferemove causes infinite loop - by m4karow - 01.10.2017, 19:06
Re: Foreach saferemove causes infinite loop - by None1337 - 01.10.2017, 19:11
Re: Foreach saferemove causes infinite loop - by m4karow - 01.10.2017, 19:15
Re: Foreach saferemove causes infinite loop - by None1337 - 01.10.2017, 19:24
Re: Foreach saferemove causes infinite loop - by m4karow - 01.10.2017, 19:28

Forum Jump:


Users browsing this thread: 2 Guest(s)