Categories
Coding Experience Fun Nerdy Talk Opinion Technical

The Butterfly Effect of Fixing Bugs!

Hello! It’s nice to see you again XD Welcome to another blog article demonstrating my progress for this week! How was your week? I hope it was good, for me It was amazing as I was quite productive -> (Read More)

So Let’s start!

Justice for Texts, Granted

In my previous blog post I mentioned this text problem where some texts were getting jumped up while others were overflowing! Well, the great detective (err.. developer) HSK, successfully investigated the problem to be linked with fonts!

What was happening in the original behavior is that, while calculating line height (because look, for rendering all those texts, we need to know the exact dimensions they occupy) with custom fonts, the heights were just a very small magnitude different from what It should be (I mean, for some texts, adding 1 to all line heights fixed the problem, but broke all other fonts)

The Solution?

Was very simple. In the original implementation, they only used the font’s height but didn’t make use of another parameter, that is called “Leading”

The vertical space between lines of type is called leading.

After simply making a change, from

virtual int getFontHeight() const { return_data._fRectHeight }
to
virtual int getFontHeight() const { return_data._fRectHeight + getFontLeading(); }
Everything was fixed, WOOHOO!
Obviously, the warlock-100 (game for which bug was discovered), became very happy, as text alignment now properly works! (Screenshot below)
fixed alignment of “The Blaster” text, now matching with it’s play button!
Merged PR link -> #5100

Game Save loading Error – Total Distortion

This is yet another bug which was discovered while playing through total distortion, where sometimes there is corruption in game properties which, when saved and loaded again, completely crash the game!

This is an interesting bug because It made me unable to progress further (and was quite annoying)

Details for this -> https://trello.com/c/TllLPBYZ/626-game-save-loading-lingo-parse-error-totaldistortion

Oh, by the way, there is a public Trello board for tracking bugs and issues. You can always look there to know the current state of the engine!

So again, after lot of digging through I finally found the rootcause of the problem! That was a simple comparison check:

In certain parts of games, two similar but different types were being compared (for example, you can compare Integer 4 and string “4” and expect them to be true). Similarly, it was happening that two datatypes of Director Engine Symbol and String were being checked for equality, now being similar but also different, ScummVM didn’t take them into account and just returned false even for similar ones and thus, this small issue was giving big troubles! The Fix was very simple, that is to tell scummvm to treat Symbol and String comparison by “String” way!

Just for reference, a symbol in Director looks like #mysymbol, while a string is “mysymbol” like if you also have doubts that WHY? aren’t they same?? Well they are not.. let’s see what books say about this!

A Universal “Name Constant”
Symbols are something special to Lingo. They’re sort
of a “name constant,” giving you the portability of
string names minus the computational and data
overhead.

Lingo! (Tab Juilius)

Well, Let’s not go deep into the technical aspect of this, just know that they are similar but distinct!

And finally, here’s the fix: #5107

Butterfly Effect of Fixing Bugs

Bonus section! So I remember my mentor said this when I was starting to submit a proposal in GSoC! He told me:

and look, we are not testing GAMES, we are testing Director, so, there is a beautiful side effect they break because some feature we implemented is not correct or absent 
How is this relevant to my previous bug fix? Well, those words were precisely correct, they couldn’t be any more truth to what I do every day! The more I get into finding and fixing bugs, the more I realize that they are fixing many other things that I have no idea of!
This was very much visible in my last bugfix of symbols comparison, where once I fixed it and was testing game again, I observed that many big and small bugs were also fixed, and the game suddenly got a lot-lot better… Just like that!
That’s why putting emphasis on the butterfly effect of fixing bugs, you fix one bug, It fixes another, and that.. fixes another as well! (The converse is also true, make one bug, destroy the whole program)!

Listing out things that were successfully working in total distortion:

shops and calling feature working!
video sequencer now opening without crash!

Finishing what I started – Meet Mediaband’s UnDo Me

Now comes the last and most nostalgic part! One of the first things I worked on after being introduced to ScummVM is Quicktime Video playback!

Yes, I cannot remember exactly if this was my 2nd or 3rd task, but what I can remember is this was one of the things that gave me an, even more, deeper understanding of the codebase and made me familiar with how things work when you play video!

Anyways, so in the month of March-April, I was given the task to implement custom playback rate and reverse playback for Quicktime Videos, you can just think of it as how your video player can be set to play at twice the speed skipping boring university lectures (Yes, I have done it too, personal experience), but here It was no movie player, here it was ScummVM, and we needed this functionality for this game meet-mediaband where one of the movies were using a miniature sort of video-player with different playback speed and this was all a part of UnDo Me.

A little bit about “UnDo Me”

well, it is a very simple game where you can choose between four romances for our lady and have two controls, “Ice” and “Fire” for going passive or aggressive to different situations and scenarios that will be played throughout the movie, while there are two buttons “Un” and “Do” for reversing/resetting story and for quickly going forward)! This clever game was implemented by seeking different parts of our QuickTime movie! You can even watch this youtube video of gameplay

Continuing on,

In the months of March-April, I implemented this custom playback but didn’t implement/integrate this with UnDo Me (the very game for which it was made), fast forward to 2 months, and suddenly we got a fully explained video of mechanics, and how it looks like, sev (my mentor) asked me to look into it and I knew, This is destiny… (Well I was supposed to finish it either way :P)

Fast forward to another sleepless night and voila! We have our UnDo Me working with all the controls working and a smooth experience! YAY!

Also, special thanks to fracturehill and their PR #4965 that made this integration possible (because setting custom rate audio was not implemented when I first started looking into video playback)! Not only that I must thank him for finding a bug that I mistakenly thought was due to their work(In the end, it was me who didn’t debug it thoroughly)! And being so helpful!

undome in scummvm!

Link to PR – #5118

Ending Notes

As usual, thanks a lot for reading all the way up to here! Apologies for any grammatical, or writing mistakes (My Grammarly is screaming right now), and with this see you next week!

Categories
Coding Experience Technical

Because spaces should have height too!

Greetings! This is yet another blog documenting my work for this week. Also, before starting, I want to mention that this will be slightly more technical!

So let’s start!

Wrapping Loose Ends

This section is in continuation of my previous blog post – https://blogs.scummvm.org/hsk/2023/06/10/i-am-a-developer-and-i-add-bugs-in-code/

I mentioned this something’s something riddle but didn’t go into technical terms, so here I am mentioning it:

Also, read that blog if you haven’t still, or skip this section.

The task was to modify how the frame’s loading in the director engine works. This is quite a big and deep change that changes the fundamental of the engine.

So currently, in the Director engine, we load all the frames before starting a movie (or a game in layman’s terms), now this was good till now, but it has some disadvantages that were not yet explored. (Until we found that genius game exploiting it).

So, in conventional frame loading, It used to work by first precalculating all frames, creating an array where we have all the frames loaded by frame number and this was later on used in all parts of the engine (rendering, configuration, properties assignment/change, etc.), This was good however it has the disadvantage of being inflexible, that is, it was all good and fine when we precomputed all frames and use them, because conventionally these frames were not meant to be changed anyways.. (ie imagine a developer created a game with a rolling ball, means the engine created series of the frame with this information, etc..) but once we have that all, we don’t need to worry about things changing in-between.. well sure they can and if you have any idea you will argue that things can change with code, and that is correct but only the case when the particular is set to be Puppet (A command which give control to script about different properties of object, or sprite without bothering to see how they moved in original movie). In essence:

A non-puppet (or not controlled by script) is meant to behave like how the frames define them, ie, if Frame 1 says the object ball is at position 10, 10, then Frame 2 says it is now at position 20, 20, then there’s no doubt that it will be the same! (Because that’s how the movie is created). or, giving a better example, imagine you created a gif (or series of images), now to view its motion, a player (or any digital software) can preload first all images in memory and then serially display them.. It doesn’t have to bother fetching each image at every frame!

We thought it too until this game called “Total Distortion” broke the way we used to see the director! This game used a peculiarity (or I mentioned in the last post as a bug) of the director, which made it have changes on frame independent of how the movie defined it! (i.e., runtime changes).. so now the concept of loading everything at the start and then sequentially playing failed because this game at runtime was making some changes which, when doing precomputation, were not visible (As they are overridden because that sprite is never announced as puppet)

What’s the solution?

On-demand frame loading! Yes, as per the name already suggests, this type of frame loading doesn’t compute all frames at once but instead do it when required! Ie it only fetches the frame that is to be displayed next, then add in the information that is changed and finally you have your new frame!

One important thing to mention is that Director engine works on concept of deltas, that is if it only records the difference in a frame from previous one! This saves quite some storage and prevent duplication of data, and due to this concept of delta’s do we need to have ondemand loading, because now We will overlap the changes of next frame to current state of frame (which might be modified externally), rather than precomputing all frames and always replacing whole state of frame at once!

PR Link – #5089

Also linked to this pull request is #5074, merged the day after my last blog post! This built some initial groundwork for the on-demand frame and D6 auto puppet property!

Fast forward to the present:

Let’s break down this week’s work into these sections and fun short stories so it becomes easier to read!

GSoC is all about Mentorship and Communication:

Yes, you heard it right! I cannot emphasize this because this program is about mentorship and communication. How well you can communicate and fulfill the tasks given by your mentor and how efficient you are will decide if you are being able to contribute or not! In this regard I got hard times, especially at the start when there were issues in communication, often time I asked the same questions again and again before getting something done.. and in that sense A big shoutout to super-mentor sev for having the patience to deal with such a clumsy student, and for quotes that I will be using throughout my coding career)

Leaks are annoying (and dangerous):

Part of my work here also includes finding/making sure that there are no memory leaks! If you don’t know what is memory leak then it is:

In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released.
Memory leak, although often times seen harmless (in way that there is no immediate errors, etc) are not good when they accumulates, also these are especially not good for low-end device where resources are already a problem!
So there was this problem where part of code which was responsible for opening executable files was leaking some memory in cases where the file is invalid, this was not noticeable because this problem happens at this specific corner case, and it was all good when the file is read successfully! While working on some different feature I encountered this leak and was horrified (because each leaks are really, really dangerous, especially at scummvm.. I will tell later the reason why), So i fixed this before resuming my work!
Link to commit with fix – 7d8dcebeb70776a3e388c387541c877ba6675892
Why are leaks dangerous?

Remember I mentioned something about leaks and why they are dangerous? Well the reason is, our buildbot doesn’t like them!

What is build bot?

Buildbot is a software development continuous integration tool which automates the compile or test cycle required to validate changes to the project code base.

In essence, for each change, it goes through a set of testing that tells if the changes are good enough, and here at scummvm, we believe at code quality! So anything that leaks is not accepted by build bot and thus in cases when something did leak, our build bot flags it and send lots and lots of errors.

The time when I spammed channel with leaking code..

And it has happened that I made code without checking for leaks and had a nightmare of error messages flooding the channel..

Because Spaces should have height too!

And finally, to the last section, that is fixing this bug where there were alignment issues in multiline texts!

This was observed in Spaceship Warlock https://trello.com/c/Mc8OITwf/549-spaceship-warlock-guide-line-spacing-not-respected where the alignment was off, to test this sample test movie was created to see the behavior

scummvm.png
the issue, the texts are not aligned with their buttons!
on the left is ScummVM, on right, is the original Director 4

As you can see, the different height and END tag for first column of text! It was due to this specific code

if (!hastext && _textLines.size() > 1)
height = height > 3 ? height - 3 : 0;

Which was calculating the height of each line in this text, in essence, what code says if there has been no text (ie empty line) and there is multiple lines, then shrink the height of this specific line by 3 units!

As usual, as a good developer with some responsibility, It was up to me to bring these to justice, and as usual, I did just that (by removing that check)! However this change was not very comfortable with different texts in other games, I am still testing more and improving it!

Link to pr – #5100

Bonus Fix: The Apartment 4 Font Fix

While testing for this existing patch, I found yet another bug where apartment 4 was getting font problems in text, as usual being a responsible developer it was fixed and added to pr #5100! The changes in fix:

before the patch, there is font problems in text
after the fix, fonts are good

Ending

Thanks for reading the blog, I hope it was good read! As usual apologies for any grammatical mistakes, typing errors! And that’s it for this one, look forward to my progress next week!

 

Categories
Coding Experience Fun Nerdy Talk Technical

I am a Developer, and I add bugs in Code

Quite an ironic title, right? Must be thinking I am joking, but hey! What if I say this is all true?

Now before getting to this fun story and about how exactly I am adding bugs in code, let me present to you the definition of a bug! As been talked about by my mentor!

Eugene Sandulenko (aka sev, or my mentor) said:

bug is typically a problem in code of unknown nature

And here is something which I found on Google:

A bug is an unexpected problem with software or hardware. Typical problems are often the result of external interference with the program’s performance that was not anticipated by the developer. Minor bugs can cause small problems like frozen screens or unexplained error messages that do not significantly affect usage.

I hope that makes it clear!

Now coming to the good part, I am a software developer, a GSoC’er this year, and most of the time, I resolve bugs, but sometimes I add them too!

The Story

To start with the story, first you need to understand what exactly is my work as a GSoC’er in this organization called ScummVM! So let’s start with basics:

What is ScummVM?

ScummVM is a program that supports numerous adventure game engines via virtual machines, allowing the user to play supported adventure games on their platform of choice. ScummVM provides none of the original assets for the games it supports, and expects the user to properly own the original game’s media so as to use the software legally.

This is what Wikipedia says about us, but in layman’s terms, What we do is to bring compatibility of these vintage games to our modern platforms! We do this by implementing engines in C++. These engines take in-game files, and are able to run them! If you have even a bit of idea about how Unity works, Unity is a game engine; just like that, there are very, very old studio-made game engines using which games were made! What we do is recreate these engines so that if one has the game files for their favorite old games, they can now play them using our software!

What is my Role for GSoC’23?

quoting the bulletin news board itself, it says:

  • Harishankar Kumar will work on improving Director 4 Compatibility. The goal is to reach full support for Total Distortion & The Journeyman Project. You can follow the progress for this task on Harishankar’s GSoC blog

Oh, by the way, If you don’t know. I am Harishankar Kumar XD (And nice to meet you too)

So, what I do, is to improve compatibility for Director 4 Engines. Now, the fun thing is that these engines are made by taking some real vintage game engines as a reference! (In my case, it is Macromedia Director 4, released February 28, 1994) and with these engines come their own quirks and behaviors.

Do you see where I am getting at?

Replicating the Perfect Engine

As part of replicating the perfect D4 engine, I have had to fix many bugs. These bugs were also what made me reach this point, get selected as a student, and write this blog but It is all great when you are fixing a bug that is in ScummVM by taking reference to how the original (ie Director 4) should work, but what will happen if we were to perfect our code such that it is even better than the original? (In some aspects)

Oh yes, you heard it right! So here’s the STORYTIME!

What happened?

As part of taking reference of original and how documentation, books etc says things should work (in Director 4 Engine), our software at ScummVM was developed such that it followed the rules.. however in pursuit. of this excellence, we made big mistake.. that is

Implementing something that is better than the original!

Oh yes! Now if I delve too deep into technical aspects, It will be too difficult to understand, but let’s just say there was this functionality of engine that allowed it to do something, however as part of doing something, It was also doing something else which it was not supposed to do, this something something was something that our software ScummVM was not doing (so we were good, following rules, documentation, and books) however because we didn’t do this something that the Director 4 was doing, our program has bug..

Well, to be precise, the bug was in the original Director 4, however since we perfected ourselves too much, we surpassed the original engine itself (in this feature only, It would be very, very arrogant of me to say we really surpassed the whole engine itself, if that were the case I wouldn’t be there doing something’s riddle to you)

Adding bugs

Now comes the good part, which is adding bugs! Well, this is only a figure of speech because, in reality, I was not adding bugs to this software. I was implementing this non-documented weird behavior (or a quirk) that is present in Director 4 engine, and thus doing my part as a responsible developer!

Now this is a bug of the original Director 4 because It is not how the games built on D4 were used to use.

It was either a genius or a complete idiot who used a quirk of software to do their own work and release this into production! (I still believe they are genius to use something in such a way that is written nowhere, completely unique)

Only god knows if this were intentional. However, the amount of work this adding “small” bug cannot be underestimated because it made us question the fundamentals of the engine and required some heavy changes!

But one thing is for sure, We are moving forward towards creating a perfect director experience, either its features.. or its peculiarities in the form of BUGS!

My work this week

Even as I am writing this blog, I am side by side working to implement this peculiar behavior I just mentioned, however this week, I managed to get another pull request merged, that is #5074

Not only that, this week was quite hectic with all these findings and verifying proper behaviors with respect to these non-documented quirks. I wrote several tests to check and verify their behavior in scummvm!

Ending

Thanks a lot for reading this! Do comment out your honest thoughts and opinion about this blog and follow the series for more of such interesting content!