Article Q7BA Run Crash Crash Run

Run Crash Crash Run

by
Maciej Stachowski
from The Daily WTF on (#Q7BA)

As Max entered the room, he was instantly greeted by a scorching wave of heat.

BSoD_in_Windows_1.0.png

As it turned out, even the freezing Russian weather was no match for the boiling hot atmosphere at Sturmovik Games' office. The small Moscow-based company with a humble portfolio of mobile games was just days away from a major content update for one of them. Naturally, the whole place was on red alert. Said update had been in the works for over six months, and had been widely advertised as the greatest overhaul the three year-old game had ever seen.

During those six months, Max and his two coworkers put in an insane amount of work, implementing the ever-changing feature requests, writing and rewriting swathes of code, and fighting against the buggy third-party libraries they had to use. Finally, the stress and overtime hours were about to pay off. Every deadline had been met. All they had to do was deploy the update.

Or so Max thought. The booming voice behind him brought him back to harsh reality.

"Who broke the build?!"

The dreaded question hung in the air. Max turned to find Ivan, his fellow developer, standing and looking around the room to find the culprit. With the third developer on sick leave, there weren't many other people to whom the question could be addressed.

"What do you mean?" Max asked. "It worked yesterday, and ..." He trailed off when he noticed an email that had just arrived in his mailbox:

From: Alexey <apajitnov@sturmovikgames.net>To: Icarus Flight DEV team <dev-2@sturmovikgames.net>Subject: CRITICAL Bug - game does not startThe game fails to start two out of three times. Please investigate.A.

Klaxons went off in Max's head. "What?! I ran the game a million times yesterday. It was fine!"

"Okay then, let's see it." Ivan went up to his desk with his cellphone in hand. "I just cleared it off my phone, we'll reinstall it."

The game launched and ran properly the first time they ran it. On the second launch, it crashed seconds into the splash screen.

Max stifled an expletive, his heart pounding. "Again."

Ivan tried running the app, only to have it refuse to start again.

"Again," Max urged.

That time, the game started without a hitch.

They launched it about twenty times. The pattern remained unbroken: the game started up once, then crashed twice, then started up once, then crashed twice ...

At first, Max had wondered if he could write it off as a connection problem, but the regularity of the pattern made him curious.

"Okay, this freaks me out," Ivan said. "Let's dig into the code, there's some seriously eerie stuff going on."

After a whole morning of peeking and poking at the code, Max finally felt like all the pieces of the puzzle were coming together. He double-checked the lines he'd just modified. "Either I'm right, or I've lost all concept of reality."

Max pulled the trigger and rebuilt the game. When he ran it for the first time, it worked as expected. Then, the moment of truth. He ran it a second time ...

It didn't crash. He did it. He broke the pattern. Max fell back against his desk chair with a sigh of relief.

"Hey, you fixed it!" Ivan was happy as a kid with a new toy. "What was the problem?"

"That stupid new XML save file," Max groaned.

As part of the update, management had decided that all save files for all games were to be migrated from undocumented binary blobs to a common XML-based format. Max hadn't been too pleased about the change, but he'd written some migration code to change the file format on the first startup.

"See, on the first run, the game reads the old binary file, then saves it out as XML," Max explained. "The game runs fine. Unfortunately, the new save file was broken. There was an unclosed tag right at the end."

"Oh," Ivan moaned, seeing where this was going.

"Wait, you don't know the half of it," Max said. "On the second run, the game tried to load the broken XML file, and failed. So it loaded the old binary file instead. But since the XML file was there, just broken, it got moved to the backup save location. Then a flag got set that said the save had been loaded from XML. So we had a binary file loaded, but the game thought it was running off the XML file. So it got confused and crashed."

"Man, I'm confused," Ivan muttered.

"On the third run, no XML file was present in the save directory, so the game tried to load one from backup," Max continued. "But the only XML file in that location was the broken save from before, so that failed. It fell back to loading the binary save again. Since that succeeded, it deleted the broken XML file in the backup location, then tried to move the current XML save file there. Except there was no XML file to be moved to backup, so the app crashed again. And since we deleted the backup, all we had left was the old binary blob. Which meant we were back to where we started."

By the time Max finished his explanation, Ivan's head was visibly spinning. "It's fixed now, right?"

"Right." Max smiled, wiping sweat off his brow. After braving this fire unscathed, nothing would stop them from a timely, functional release.

inedo50.png[Advertisement] Use NuGet or npm? Check out ProGet, the easy-to-use package repository that lets you host and manage your own personal or enterprise-wide NuGet feeds and npm repositories. It's got an impressively-featured free edition, too! TheDailyWtf?d=yIl2AUoC8zAWnS8wX-fCqI
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments