Jump to content

Crash for clients when using Mission Commands


Recommended Posts

I am experiencing weird crashes for clients, that do not affect the host, when using Mission Commands.

 

The following (simplified) code is causing the troubles:

 

do
local PlayerAircraft = {
	[1] = {
		name = "Huey 1-1",
		radioMenu = false,
	},
	[2] = {
		name = "Huey 1-2",
		radioMenu = false,
	},
}

local function TestFunction(ID)
end

local function PopulateRadioMenu(ID)
	missionCommands.removeItemForGroup(ID.groupID, {"Submenu"})
	missionCommands.addSubMenuForGroup(ID.groupID, "Submenu")
	missionCommands.addCommandForGroup(ID.groupID, "Hello", {"Submenu"}, TestFunction, ID)
end
	
local function CheckPlayerExists()
	for n = 1, #PlayerAircraft do
		if Unit.getByName(PlayerAircraft[n].name) ~= nil and PlayerAircraft[n].radioMenu == false then
			PlayerAircraft[n].groupID = Unit.getByName(PlayerAircraft[n].name):getGroup():getID()
			PopulateRadioMenu(PlayerAircraft[n])
			PlayerAircraft[n].radioMenu = true
		elseif Unit.getByName(PlayerAircraft[n].name) == nil then
			PlayerAircraft[n].radioMenu = false
		end
	end
	return timer.getTime() + 1
end
timer.scheduleFunction(CheckPlayerExists, nil, 2)
end

 

 

Basically I want to populate the F10 radio menus for all players in multiplayer. First comes a table that holds the name of client aircraft (and some more additional stuff in the complete mission). Then comes the function which clears the radiomenu of a player, and repopulates it (I trimmed it here, it includes many more commands, but all similar). Lastly comes a repeating codeblock that if a player aircraft exists and that has not yet its F10 menu populated, it populates the radiomenu. When a player is dead, the elseif code resets a variable, so that the radiomenu is generated again the next time this aircraft spawns again.

 

This code works perfect for the host of the mission. It also works for all other clients for the first time they spawn. Radiomenu is populated and all mission commands function as expected. When a client dies and respawns again in the same aircraft, his game and the game of all other clients excluding the host crashes simultaneously. For the host, the mission continues normally without any error messages at all. We tested this with 4 users total, with different users as host. Each time with the same result.

 

The crashlog of a client (attached) lead me to believe that the problem has something to do with mission commands. And indeed, if the function "PopulateRadioMenu(PlayerAircraft[n])" is disabled with "--", the problem ceases to exist.

 

Is there some fundamental problem with my code?


Edited by MBot
Updated to code, see post #6
Link to comment
Share on other sites

Anyone got an idea? I have spent a lot of time on a new Huey mission and it is basically complete, tested and ready. Except this "minor" issue that a respawning client will crash the game of everyone on the server. And I have no idea what the problem is.

Link to comment
Share on other sites

You say that remarking function PopulateRadioMenu eliminates the crash. That tells me one of the two statements within is causing the problem. I suspect it is the first one: removeItemForGroup. Try remarking that line and see what happens. You may find that it is not needed at all.

  • Like 1
Link to comment
Share on other sites

Yes, I had this idea as well and already tested that. Unfortunately it still crashes with the removeItemForGroup lines disabled.

 

I am sorry I can not provide more details at the moment. Usually I cut down problems to the lowest common denominator. But since this is a problem I can only verify in multiplayer with a partner, it makes the testing process a lot more tedious. I will see if I can identify some more specific details about the crash this weekend with the help of some friends.

Link to comment
Share on other sites

I'm curious if you mimic the same sort of commands via triggers, if the crash would still occur.

 

What happens if you remove the command while the player is still alive?

If you don't remove the command, does the command still exist when the player respawns? I know it is supposed to do that for some of the commands, at least with triggers.

The right man in the wrong place makes all the difference in the world.

Current Projects: Scripting Wiki, Something...

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread), SLMOD, IADScript, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Thanks to the help of a friend, we managed to isolate the problem. We tested 20 variations of removing and adding radio commands until we found out the offending combination. The crash happens for the client, if a previously existing radio submenu is removed and re-added:

 

do
local PlayerAircraft = {
	[1] = {
		name = "Huey 1-1",
		radioMenu = false,
	},
	[2] = {
		name = "Huey 1-2",
		radioMenu = false,
	},
}

local function TestFunction(ID)
end

local function PopulateRadioMenu(ID)
	missionCommands.removeItemForGroup(ID.groupID, {"Submenu"})
	missionCommands.addSubMenuForGroup(ID.groupID, "Submenu")
	missionCommands.addCommandForGroup(ID.groupID, "Hello", {"Submenu"}, TestFunction, ID)
end
	
local function CheckPlayerExists()
	for n = 1, #PlayerAircraft do
		if Unit.getByName(PlayerAircraft[n].name) ~= nil and PlayerAircraft[n].radioMenu == false then
			PlayerAircraft[n].groupID = Unit.getByName(PlayerAircraft[n].name):getGroup():getID()
			PopulateRadioMenu(PlayerAircraft[n])
			PlayerAircraft[n].radioMenu = true
		elseif Unit.getByName(PlayerAircraft[n].name) == nil then
			PlayerAircraft[n].radioMenu = false
		end
	end
	return timer.getTime() + 1
end
timer.scheduleFunction(CheckPlayerExists, nil, 2)
end

 

I added a simple mission demonstrating the problem with the above code.

 

Reproduction of the crash:

-Host select Huey 1-1

-Client select Huey 1-2

-Client select spectator

-Client select Huey 1-2 -> game crash for client

 

 

This seems to be entirely related to scripting, since radio submenus are not accessible through triggers.

 

P.S.: Thinking about it now, the crash reproduction might possibly even be reduced to simply removing a previously existing radio menu item for a client (other than the host). We didn't test that variation.


Edited by MBot
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...