Upcoming Events! Community Event Calendar

Bugsmashers: Spectator Mode Crash Written Wednesday 29th of March 2017 at 12:00pm by CanadianSyrup

As per usual, anything said during the show is subject to change by CIG and may not always be accurate at the time of posting. Also any mistakes you see that I may have missed, please let me know so I can correct them. Enjoy the show!

TL;DR (Too Long; Didn't Read)

  • Today's bug featured an interesting crash where when a player exited their ship and went into spectate mode, they would crash all players in the match including themselves.
  • The issue was caused because the item ports weren't being properly cleaned up after the player went into spectator mode and the game tried to access something that wasn't there and thus crashed the game.
  • Mark took a dive into the code to made sure the procedure for when a player exits a ship, then goes into spectator is followed correctly by having the game clean up the assets left behind after leaving the seat.
  • Mark also loves bacon and taunted us with it during the episode.

Full Transcript

Mark Abent (MA): Hey everyone welcome to Bugsmashers. I’m your host, Mark Abent. I’m a Senior Gameplay Programmer at CIG L.A. and I’m here to show you the bugs.

So, hey everyone we’re here in our fancy dancy Vanduul Swarm and we’re going to replicate this crash where if we enter spectate mode… Let’s see if I enter it. Alright I’m in spectate mode, everything works as expected, everything’s moving around, but as soon as I disconnect I should crash…. BAM! Crash. This was an interesting crash. It’s actually HUD code accessing the Item Port System. The Item Port System of course is our system which we use to connect like weapons to the player, player to the ship, all sorts of crazy shenanigans and for some reason… I should say, parent port or this particular port is garbage, it might be this… Either way it doesn’t like something, there’s some nasty parent port that’s garbage and when it accesses it, one of those is like, “Whoa! You’re accessing memory that was deleted”.

So what’s happening and why? So let's step back, close all the games and we’re going to rerun it and explain the issue.

So, oops I ran the wrong thing, I clicked too fast. Come on, there it goes alright. So what’s happening here is anytime we sit into a seat, we have to switch the player to this linked state. It’s in this actor linked state right here and this is basically the area that you hit when you enter or, when you get removed from seat you’ll get a linked event and a delinked event and under normal situations you should be going here.

So if you want to go into a ship you should get the link event, so to get this processed we want to do something like enter spectate mode which leaves the seat and goes to this bit of code. What these bit of code here is we basically take the player and we don’t attach them to exactly an item port, we just set his parent. What that allows us to do is have his radar communicate to the vehicles radar and have the vehicles radar communicate to the players radar, it’s like this is how the two communicate to the items and subitems that a player's item could see on the ship and vice versa and that’s what basically this bit of code does and this bit of code on the delink will clean it all up so we completely separate. If we don’t get the proper delinking and unlinking, or linking and unlinking, we’ll never reach these bits of code and so if we have the ship and we delete it, but the player never got the delink event, and then we switch to observer mode, this is going to leave a dangling pointer in the item port code because we never cleaned up. So when we sit down we tell the player that you’re now linking to the vehicle. We switch to observer mode, we move the player, delete the vehicle, but we never got the delink thing so the player never cleaned up his item ports so he’s still pointing to this memory that is gone and so we need to make sure we get to here before we go to observer mode.

The observer code is… So if I request the observe, server will get it, process it, ultimately come here and what it’s doing is some area of the code when we delete this ship, it will exit him, but before it could actually get to the link state it’s just completely setting a state machine to something completely else so even if we remove him from the seat, this bit of code just ignores all that stuff and directly assigns his new state machine and we never get the delink.

The fix of course is to make sure that we properly exit the seat so that the state machine could send the required delink, we could remove all the item port pointers and then we’re not pointing to invalid memory and we’re actually out of the seat correctly and then we can now then snap to the required spectate mode.

So we’re going to hit recode… Compiling place… As that code goes up and running, bacon. Hear that crunch, that’s good bacon. Alright recode is finished. So now we can connect to the server and of course connecting is going to take a bit of time so I wonder what we can do, oh I know! Bacon. Yes, that’s right you’re just going to watch me eat bacon for the next minute. I’m okay with this. Bacon.

Alright we’re back into the game, put the bacon aside and now we’re going to go to spectate mode and we properly exited the seat. We went to observer mode and now everything should have cleaned up correctly so when I exit I should not crash from that particular crash. Woo! As you can see I haven’t crashed, it’s now loading the main menu, all is well. So you can go to spectate mode, exit the game, come back, get out of  spectate mode, go into a seat, do whatever to your hearts connect and you’ll no longer crash because we have no more dangling pointers. Hope you guys enjoyed. Time for more bacon.

As you guys saw we had a fun little bug there where you join in your coop and you want to enter your spectate mode and all of a sudden everything's fine and dandy, you leave the game and bam everyone crashes. Spectator mode wasn’t taking us out of the seat correctly and in fact was just kicking the vehicle away and moving us into spectate while everyone thought we’re in the seat. So now spectate mode will actually remove you from the seat before moving you into spectate mode. Now no more crashes when anyone leaves and all is good. Hope you guys enjoyed, until next time.


Director of Transcripts

A polite Canadian who takes pride in making other peoples day brighter. He enjoys waffles with Maplesyrup, making delicious puns and striving for perfection in screaming at the T.V. during hockey games.