NullPointerException in ChannelImpl.unicastData

Hi, I think that Project Darkstar is an awesome tool, but I’m having a little problem with the network communication.

Sometimes when I call SimTask.sendData to send data from the server to the client, I get an exception of the following form:


WARNUNG: Exception on task execution:
  target: org.akoller.sgs.textadv.Boot
  method: userJoined
  declared on: com.sun.gi.logic.SimUserListener
java.lang.NullPointerException
        at com.sun.gi.comm.routing.impl.ChannelImpl.unicastData(ChannelImpl.java:121)
        at com.sun.gi.logic.impl.SimulationImpl.sendUnicastData(SimulationImpl.java:496)
        at com.sun.gi.logic.impl.DeferredUnicast.execute(SimTaskImpl.java:574)
        at com.sun.gi.logic.impl.SimTaskImpl.processDeferredCommands(SimTaskImpl.java:536)
        at com.sun.gi.logic.impl.SimTaskImpl.execute(SimTaskImpl.java:188)
        at com.sun.gi.logic.impl.SimThreadImpl.run(SimThreadImpl.java:105)

The data the server wanted to send never arrives at the client in such a case. The exception occurs unpredictably – sometimes the data sending goes through, but rarely enough to make my game unplayable.

This already happened with the original SwordWorld system from the tutorial (after I had changed makeReference to lookupReferenceFor to get it to run). One thing that seemed to eliminate these exceptions in SwordWorld was to call openChannel(“GAMECHANNEL”) to get a new ChannelID for each call to sendData. But (a) the documentation says the lifetime of a ChannelID is from start to finish of a run of the server, so I shouldn’t need to acquire new ChannelIDs for each sendData call, and (b) it doesn’t really help after all – in my little experimental text adventure that I’ve been developing, which doesn’t do much that SwordWorld doesn’t at this point, the problem comes back even then.

The problem comes from calls to sendData, not from userJoined as the example above seems to suggest; it just occurs there because I send a welcome message to the user when they join the game.

Can you give me any advice on how to deal with this problem?

Hm.

My guess is that you are trying to send the data to the user befoer the user is joined. Are you waiting for userJoinedChannel callback? If so then thre may be a timign issue I need to look into. If its timing then inserting s amll sleep before the send aught to fix it BUT thats a hack so Id like to make sure it really is a bug first…

I just figured out what my problem probably was. I tried to send data to a null UserID. Sending to simTask.getUserID() instead seems to have fixed the issue. I still don’t know why I had problems with the SwordWorld demo server, but perhaps it was something similarly trivial too.

:-[ :-[ :-[

I’m sorry for wasting your time with such a silly mistake. Now that I’ve figured out how to use a debugger on the SGS, I’m going to hunt my own bugs more thoroughly next time.

Not a problem, its how we all learn. 8)