getCurrentRoom() null at extension init (sometimes)

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

overmind
Posts: 26
Joined: 11 May 2008, 08:27

getCurrentRoom() null at extension init (sometimes)

Post by overmind »

After I updated smartfox to last version, i have this error (2-5 times per day at 10,000 room creations):

TypeError: Cannot call method "getId" of null

at this command:

roomId = _server.getCurrentRoom().getId();

This command is on init() function at room's extension.

Rooms are created from users or dynamically from zone extension.

Server is running more than 7 months without this error. It was started yesterday when i updated to 1.6.9.
overmind
Posts: 26
Joined: 11 May 2008, 08:27

Post by overmind »

Also at the same time this warning started: (5-10 times per day...not in same rooms)

INFO | jvm 1 | 2010/09/18 02:32:44 | 02:32:44.035 - [ WARNING ] > Error in extension [ games/framework.as ]: TypeError: Cannot call method "shutdown" of undefined (games/framework.as#1699)


any help? anything i can do? or to think about?
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

Have you also updated your Client API (that came with the 1.6.9 package)?
Smartfox's forum is my daily newspaper.
overmind
Posts: 26
Joined: 11 May 2008, 08:27

Post by overmind »

Yes i updated client too. These warnings are on room creations/destroys for some reason...
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

It does seem odd that you started getting this warning with the latest update. It could be possible that some of your clients are still using the old client API (just a guess) - due to their cache not clearing out yet.

Or perhaps it is an introduced bug in 1.6.9 patch. It does seem odd that _server.getCurrentRoom() would return null for a dynamically added room extension.

If you could provide more detailed information how you dynamically add a new room + extension? Can it be reproducable? Thanks.
Smartfox's forum is my daily newspaper.
overmind
Posts: 26
Joined: 11 May 2008, 08:27

Post by overmind »

It is not reproducable. It happens rarely at random times...also for some reason these extensions remain in the memory and catching internal events for all users of the zone (join exit etc.) . My game extension sends one message on userJoin(only on user that joins game) and i see that message every time that i am connecting to the zone default room or other game rooms! (from roomid that was destroyed yesterday) i made handleInternalEvent function to return if currentRoom == null to avoid this!

Client side room creation:

var roomObj=new Object();
roomObj.name=roomName;
roomObj.isGame=true;
roomObj.exitCurrentRoom=false;
roomObj.extension=new Object();
roomObj.extension.name=myParams.eN;
roomObj.extension.script=myParams.eS;
roomObj.maxUsers=maxUsers;

sfs.createRoom(roomObj);

(user is automatically joining)

Server side room creation:

HashMap roomParameters = new HashMap();
roomParameters.put("name", roomname);
roomParameters.put("isGame", "1");
roomParameters.put("maxU", maxPlayers + "");
roomParameters.put("xtName", extensionName);
roomParameters.put("xtClass", extensionScript);

room = helper.createRoom(zone, roomParameters, u, roomVars, null, true, true, true);

helper.joinRoom(_uid, fromRoom, roomid, false, "", false, true);


Moreover, i put UseConcMarkSweepGC option at the same date as smartfox updated i dont know if it is related. Also, i think that this happens if dynamic room is created and user disconnects at the next milliseconds (so room get destroyed immediately but I am not sure). Anything that could help would be my pleasure to listen.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

It sounds like the update didn't go very well...
What was your server version prior the update?
The 1.6.9 patch requires 1.6.6 or higher and the release note indicate that it must the 1.6.6 from the installer.

If your 1.6.6 was already coming from an older patched server this update won't work.
Lapo
--
gotoAndPlay()
...addicted to flash games
overmind
Posts: 26
Joined: 11 May 2008, 08:27

Post by overmind »

it is SFS_PRO_1.6.6 from the 1.6.6 installer, and it was up to dated to the last version. I have solved all issues with if (_server.getCurrentRoom() == null) {return;}

the only remained error that never have seen it before 7 months, with thousands of users every day is that: TypeError: Cannot call method "shutdown" of undefined

(also nothing changed in my extensions)
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Do you have any other details of that error? Like a stack trace? Line number etc?
Lapo
--
gotoAndPlay()
...addicted to flash games
overmind
Posts: 26
Joined: 11 May 2008, 08:27

Post by overmind »

function init()
{
try
{
roomId = _server.getCurrentRoom().getId();
}
catch(e)
{
trace("error at as init: " + e)
}
}

function handleInternalEvent(evt)
{
if (_server.getCurrentRoom() == null)
{
trace ("NULLROOM :" + currentRoomId + " quiz")
nullRoom = true;
return;
}

...........code

currentRoomId = evt["room"].getId()

.............code
}

trace:
INFO | jvm 1 | 2010/09/24 01:09:55 | [games/quiz.as]: error at as init: TypeError: Cannot call method "getId" of null
INFO | jvm 1 | 2010/09/24 01:09:55 | [games/quiz.as]: NULLROOM :undefined quiz
INFO | jvm 1 | 2010/09/24 01:09:55 | [games/quiz.as]: NULLROOM :undefined quiz
INFO | jvm 1 | 2010/09/24 01:09:55 | [games/quiz.as]: NULLROOM :undefined quiz
INFO | jvm 1 | 2010/09/24 01:09:55 | [games/quiz.as]: NULLROOM :undefined quiz
INFO | jvm 1 | 2010/09/24 01:09:56 | [games/quiz.as]: NULLROOM :undefined quiz
INFO | jvm 1 | 2010/09/24 01:09:57 | [games/quiz.as]: NULLROOM :undefined quiz
INFO | jvm 1 | 2010/09/24 01:09:57 | [games/quiz.as]: NULLROOM :undefined quiz
INFO | jvm 1 | 2010/09/24 01:10:01 | [games/quiz.as]: NULLROOM :undefined quiz
(last lines repeated thousand times for all users that were joining rooms in this zone)

Is there anything i can to to destroy this dynamic room extension that has no room and catch all zone events?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

calling getCurrentRoom in a try/catch is not a very good idea.
The fact of the matter is that this function is only applicable when you run a Room-Level extension.
It returns the Room where the Extension is attached to.
If your extension is at Zone Level it will always return null.
Lapo
--
gotoAndPlay()
...addicted to flash games
overmind
Posts: 26
Joined: 11 May 2008, 08:27

Post by overmind »

it is the same behaviour if i have it in try catch or not.

My extension is at room level this is my problem....the extension is loaded at dynamic rooms...and never get unloaded as the room get destroyed!!!! and the worst is that it acts like a zone level extension after room get destroyed!

it is happening very rarely 1 time after 500-1000 created rooms...it never happened before the update!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

This is probably because you have created a memory leak, otherwise it shouldn't happen.
When the destroy() method is invoked you will need to remove any resources that might continue to reference your extension such as Threads, listeners and things like that.
Lapo
--
gotoAndPlay()
...addicted to flash games
overmind
Posts: 26
Joined: 11 May 2008, 08:27

Post by overmind »

i dont think it is memory leak
i had put a clear extension without code, only getId of currentRoom (at init) and i still getting the error

INFO | jvm 1 | 2010/10/08 08:24:53 | 08:24:53.565 - [ WARNING ] > Could not assign extension [ game ] to Room id= 731
INFO | jvm 1 | 2010/10/08 08:24:53 | [games/gameFramework.as]: error at as init: TypeError: Cannot call method "getId" of null
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

show the relevant extension code please
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply