Page 1 of 1

Weird issue

Posted: 12 Sep 2011, 18:49
by 3slices
I am having a weird issue.
Let me explain what I am doing:

I am following closely the Advanced Chat sample. I am currently learning the roomlist, usercount and userlist things. And here is where I have this weird issue.
For monitoring reasons I have a log textarea where I send all kind of stuff to to monitor what is going on. So what I want to do is to send the room name and the current number of users into my log window.

For this I am using the "getUserRoom" function which is also in the example:

Code: Select all

private function getRoomLabel(room:Room):String
{
	return room.name + " (" + room.userCount + "/" + room.maxUsers + " users)" + (room.isPasswordProtected ? " *" : "");
}
I am adding my code for logging, so it looks like this:

Code: Select all

private function getRoomLabel(room:Room):String
{
	logdataprovider.addItem(room.name + ": "+ room.userCount);
	return room.name + " (" + room.userCount + "/" + room.maxUsers + " users)" + (room.isPasswordProtected ? " *" : "");
}
Now when I run this, I am getting a weird result: While there are only 3 rooms altogether, in my logwindow one room gets doubled.
In my roomlist window I have following rooms: The Lobby, Lobby2 and Lobby3

In my logwindow I have: Lobby3, Lobby3, Lobby2 and The Lobby.

When I add a new room from the backend (name: Lobby4) I get the result that I get: Lobby4, Lobby4, Lobby3, Lobby2 and The Lobby.

Somehow the last room alwas appears double in my logwindow. But why is this?y

The functions itself are working as they should. My roomlist shows the rooms and the users in the rooms. Only my logwindow shows this last room doubled.

Any explanation for this?

Posted: 12 Sep 2011, 20:21
by rjgtav
The problem is maybe in the way you're logging. What you should do is, everytime a room is updated, you clear the log list and loop through the roomList.

Posted: 13 Sep 2011, 14:42
by 3slices
Thanks for your reply. However I don´t think that your suggestion is the solution. The issue persists and is not depending on what commands get executed within the "getRoomLabel" function.

In fact when I simply have it show an alert ( Alert.show(room.name); ) then I get 3 alert popups: "The Lobby", "Lobby2", "Lobby2", while there are only "The Lobby" and "Lobby2" as rooms.

For a weird reason theh "getRoomLabel" function gets executed 1 more time after it should be done already.

Maybe it has to do with the other weird bug that I have discovered:
http://forums.smartfoxserver.com/viewto ... 0314#50314

Lets say if following ids have been assigned to rooms: id0, id1, id3 and the internal function in SFS/SFS Api calculates id0-id3 = 4 rooms when in fact there are only 3, this could result in such a behaviour that such a function gets executed too many times.

But this is just a guess. Still looking for a solution.

The ArrayCollection dump itself is fine BTW. The array only shows rooms as it should.

Posted: 13 Sep 2011, 17:04
by 3slices
I have just tested the issue with the the Advanced Chat sample.
I would be glad if anybody could either confirm this or explain to me this behaviour as I cannot understand it.

In AdvancedChat.as find declaration of "getRoomLabel" and simply insert "Alert.show(room.name);" before the return statement.

The "getRoomLabel" function will get called automatically for every item in the roomlist, at least this is my understanding of the labelFunction function.

If you have added the alert statement, then you will likely experience something similiar to this:

I am connecting to the GameLobby zone. In my zone I have the rooms "The Lobby", "Test2" "Test".
Now when the client connects I get following popups: "The Lobby", "Test2", "Test", "The Lobby", "Test2", "Test", "The Lobby", "Test2", "Test", "The Lobby", "Test2", "Test", "The Lobby", "Test2", "Test", "Test". The most weird thing is that the last 2 popups are both "Test" and "Test".

This is very very weird.

Posted: 14 Sep 2011, 06:54
by Bax
This is due to the way the room list is rendered, it seems the labelFunction is called multiple times on the same items. This shouldn't be an issue, because that function is used by the List component only, to render the items.

Posted: 14 Sep 2011, 08:00
by 3slices
I am wondering if this is a SFS bug or an Actionscript bug?
As the labelFunction is intended for holding processing logic for the list, it is a bit weird that it gets called multiple time. It would never be really safe to rely on data returned by this function.

From what I understand the function should not get called multiple times for the same item.
Can you explain what is the reason for this?

Posted: 14 Sep 2011, 11:33
by Bax
This has nothing to do with SFS. It's the internal behavior of Flex components.