NegativeArraySizeException during SFSApi.createRoom

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 09 Jul 2019, 08:54

Hi, do you have any idea, in when does it happen? There is a relevant part of the stack trace:

Code: Select all

Job (DEFAULT.6da64b5bd2ee-4a7df607-0bf3-407a-96cd-2debf92389ff threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NegativeArraySizeException] at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) Caused by: java.lang.NegativeArraySizeException at com.smartfoxserver.v2.util.DefaultPlayerIdGenerator.init(DefaultPlayerIdGenerator.java:25) at com.smartfoxserver.v2.entities.SFSRoom.setGame(SFSRoom.java:354) at com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoom(SFSRoomManager.java:120) at com.smartfoxserver.v2.entities.SFSZone.createRoom(SFSZone.java:257) at com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:736) at com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:710)
...


We are using SFS 2.13.4
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Lapo » 09 Jul 2019, 14:12

Hi,
the stack trace doesn't look very familiar. In particular the references to the org.quartz.* classes look alien as we don't use any of that in SFS2X. Unless this is something used by Jetty, which I am not aware of... yet the stack trace doesn't seem to indicate this is a call running in Jetty.

Additionally the error is thrown in one of those classes ( org.quartz.core.JobRunShell ), so I have no idea what might be happening.
Are these libraries you've added with your Extension?
Also what SFS2X version is this?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 10 Jul 2019, 07:59

There is a task, which is run in different thread, that is creating new rooms.

As you might see, from the stacktrace, the exception occcurs inside
Caused by: java.lang.NegativeArraySizeException at com.smartfoxserver.v2.util.DefaultPlayerIdGenerator.init(DefaultPlayerIdGenerator.java:25)


The " com.smartfoxserver.v2.util" part indicates, that it is related to the SFS.

Please check the relevant part of the stacktrace again

Code: Select all

...
Caused by: java.lang.NegativeArraySizeException at
com.smartfoxserver.v2.util.DefaultPlayerIdGenerator.init(DefaultPlayerIdGenerator.java:25) at com.smartfoxserver.v2.entities.SFSRoom.setGame(SFSRoom.java:354) at com.smartfoxserver.v2.entities.managers.SFSRoomManager.createRoom(SFSRoomManager.java:120) at com.smartfoxserver.v2.entities.SFSZone.createRoom(SFSZone.java:257) at com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:736) at com.smartfoxserver.v2.api.SFSApi.createRoom(SFSApi.java:710)
...


I am looking forward hearing from you soon.
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Lapo » 10 Jul 2019, 08:40

Can you show us the code that creates the Room(s)?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 10 Jul 2019, 09:04

Code: Select all

    public Room createLobbyTournamentRoom(BgUser user, String name, long tourId, boolean registerUser) throws ResultException
    {
        Tournament tourDb = TournamentService.GetTournamentById(tourId);
       
        //Create game room
        Zone gameZone = getParentZone();

        CreateRoomSettings crs = new CreateRoomSettings();
        crs.setGame(true);
        crs.setName("Tournament " + tourId);
        crs.setDynamic(false);
        crs.setMaxUsers(tourDb.getMaxUsersCount() + 500);
        crs.setMaxSpectators(500);
        crs.setAutoRemoveMode(SFSRoomRemoveMode.NEVER_REMOVE);
       
        String extensionName = null;
       
        if(tourDb.getTournamentType_() == TournamentTypeEnum.SITANDGO.getId())
        {
            crs.setGroupId(SFSConst.SFS_ROOM_GROUP_SIT_N_GO + tourDb.getCurrency().getCode().toLowerCase());
            extensionName = SitNGoLobbyRoomExtension.class.getCanonicalName();
        }
        else
        {
            crs.setGroupId(SFSConst.SFS_ROOM_GROUP_TOURNAMENTS + tourDb.getCurrency().getCode().toLowerCase());
            extensionName = TournamentLobbyRoomExtension.class.getCanonicalName();
        }

        List<RoomVariable> roomVariables = new ArrayList<>();
        ISFSObject genVars = new SFSObject();
        genVars.putLong("tid", tourId);       
        RoomVariable r2 = new SFSRoomVariable(SFSConst.SFS_VARIABLE_GAME_DATA, genVars);
        r2.setGlobal(true);
        r2.setHidden(false);
        roomVariables.add(r2);

        crs.setRoomVariables(roomVariables);

       
        Map<Object, Object> roomProps = new HashMap<>();
        roomProps.put(SFSConst.SFS_PROPERTY_TOURNAMENT_ID, tourId);
        crs.setRoomProperties(roomProps);

        CreateRoomSettings.RoomExtensionSettings ext = new CreateRoomSettings.RoomExtensionSettings(SFSConst.SFS_GAME_SERVER_EXTENSION_PATH, extensionName);

        crs.setExtension(ext);
       
        Room createRoom;
        try {
            createRoom = getApi().createRoom(gameZone, crs, user.getSfsUser(), false, null);
        } catch (SFSCreateRoomException ex) {
            trace(ExtensionLogLevel.ERROR, ExceptionPrinter.ExceptionToString(ex));
            return null;
        }
        ...
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Lapo » 10 Jul 2019, 09:35

I think there might be something strange going on at this line:

Code: Select all

crs.setMaxUsers(tourDb.getMaxUsersCount() + 500);

Are you sure this is a positive number?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 10 Jul 2019, 11:13

Lapo wrote:Are you sure this is a positive number?


It was not. The property was MaxInt so MaxInt + 500 is negative number. I have fixed the issue, BUT same exception is being thrown anyway.
This is the content of CRS:
CRS.PNG
(22.74 KiB) Not downloaded yet


Do you have more ideas? :)
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 10 Jul 2019, 11:21

When i set maxUsersCount to 1 000, it works. It does not work when set to 100 000. Is there any limit? I have not found any in the documentation
http://docs2x.smartfoxserver.com/api-do ... tings.html
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Lapo » 11 Jul 2019, 09:54

Jochanan wrote:When i set maxUsersCount to 1 000, it works. It does not work when set to 100 000. Is there any limit?

Technically there are no limits, though common sense would suggest 100K users in the same Room is not a good idea :)
Unless if it's an MMORoom, in which case, no problem.

Anyways I don't see any issues in creating a Room for 100K Users. I don't get any errors.
What errors do you get?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 11 Jul 2019, 10:42

I get the same error. NegativeArraySizeException.
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Lapo » 11 Jul 2019, 15:08

Last time you showed the code to create the Room and it was a server-side creation. If you're on the server-side it will work.
What I suspect is that you're trying to create the Room via a client side API call.
If that's the case you must keep in mind that the maxUsers property is transmitted as a Short integer (16 bit) therefore it's max value should be < 65536 (2^16). Passing a bigger value will probably result in a negative value, because the negative bit is set.

You could still create the Room from server side, if this is a real use-case, though I need to stress that it doesn't make any sense to set that many users for a single Room, unless it's an MMORoom.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 12 Jul 2019, 11:24

Lapo wrote:If that's the case you must keep in mind that the maxUsers property is transmitted as a Short integer (16 bit) therefore it's max value should be < 65536 (2^16). Passing a bigger value will probably result in a negative value, because the negative bit is set.

Did you mean 32767? Java does not have unsigned types (https://docs.oracle.com/javase/tutorial ... types.html)

short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As with byte, the same guidelines apply: you can use a short to save memory in large arrays, in situations where the memory savings actually matters.
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 12 Jul 2019, 11:24

In any case, i think, that this information needs to be in the documentation. Additionally, it would be nice, if SFS actually does some sanity checks and throws its own exception with this information.
Jochanan
Posts: 79
Joined: 11 May 2018, 09:12

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Jochanan » 12 Jul 2019, 11:26

Lapo wrote:Last time you showed the code to create the Room and it was a server-side creation. If you're on the server-side it will work.


How do i create a room via server-side creation?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NegativeArraySizeException during SFSApi.createRoom

Postby Lapo » 12 Jul 2019, 18:04

[quote=Jochanan]Did you mean 32767?[/quote]
Yes, my bad.

In any case, i think, that this information needs to be in the documentation.

We discuss this in the documentation in several places. Both regular and game Room size need to be within reasonable limits otherwise the amount of broadcast will saturate the largest of networks. More importantly it will overload the clients with too much traffic.

Additionally, it would be nice, if SFS actually does some sanity checks and throws its own exception with this information.

Sure, I've added a note in our TODO list

How do i create a room via server-side creation?

I don't understand the question. You have posted an example of server-side room creation yourself, a few posts ago... that's how.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 54 guests