Page 1 of 1

onRed5ConnectionStatus chat sessions remove for each bug

Posted: 06 Jul 2009, 16:19
by vazor
In AVChatManager.as:
onRed5ConnectionStatus
There is a for each loop here that iterates on chatSessions and calls stopChat(). stopChat() uses delete on a key in the chatSessions array. I have seen undefined and erratic behavior from Flash when this happens, including skipping all the rest of the elements in chatSessions.
This may not be causing any big problems, but it looks like a potential bug.

Posted: 07 Jul 2009, 10:48
by Bax
We made a test, removing items from an associative array, and everything seems to work fine. Have you additional details on the erratic behavior you are experiencing?

Posted: 07 Jul 2009, 12:36
by vazor
It seems that the erratic behavior does not show up in test cases where keys in the array are continuous and consecutive. For example, uncomment the _array[3] line and this test will work, but leave it commented out and a value will be skipped:

Code: Select all

		var _array:Array = new Array();
		_array[0] = {"id":0};
		_array[1] = {"id":1};
		_array[2] = {"id":2};
		//_array[3] = {"id":3};
		_array[4] = {"id":4};
		for each( var val in _array )
		{
			trace("val.id:"+val.id);
			delete _array[val.id];
		}
		for each( var remaining in _array )
		{
			trace("remaining.id:"+remaining.id);
		}

/*
output (Flash CS4 v10.0):
val.id:0
val.id:1
val.id:2
remaining.id:4
*/

Posted: 07 Jul 2009, 13:02
by Bax
What you say is valid for indexed arrays, but chatSessions is an associative array, where the key is a string (the session id). Change your test like this:

Code: Select all

var _array:Array = new Array(); 
_array["id0"] = {"id":0}; 
_array["id1"] = {"id":1}; 
_array["id2"] = {"id":2}; 
//_array["id3"] = {"id":3}; 
_array["id4"] = {"id":4}; 

for each(var obj:Object in _array) 
{ 
	trace("obj.id:"+obj.id); 
	delete _array["id"+obj.id]; 
}

for each(var remaining:Object in _array) 
{ 
	trace("remaining.id:"+remaining.id); 
}
No item is remaining inside the array.

Posted: 07 Jul 2009, 14:06
by vazor

Code: Select all

_array["k0"] = {"id":"k0"};
Ah, yep, you are correct. Sorry for the trouble.