Invisible Ship/Disappearing Graphics Bug

The next update that you get (both Altarian Prophecy and Gal Civ 1.2) will have the fix for the invisible ship bug. 

It was, as I had surmised, deep in the guts of Pear, our code library.  It's one of the few places where the person who wrote most of Pear did not have any kind of warning or debug message that bad things were about to happen in memory (in this case, run out of allocated memory).  Since it was a memory problem, I had to reproduce the problem first, then work backwards to try to figure out what had gone wrong.  It's not one of the more fun things about programming. 

If you're interested, there was a set number of unique encoded graphics that we could load into memory, specifically 256.  This includes all the graphics that are in the .mdl files, the .mtd files, the .tiles files and the .fnt files.  So the reason that it didn't happen to everyone is if you skipped several levels of ships (or never got past a certain level), you wouldn't get the bug because it was below the magic #256.  But as soon as you tried to create an object with image #257, you got the invisible ship or planet or whatever.  

So I had to add code that would detect when it was about to run out of room, and make room for it.

We've got a few more things that we want to put in the next updates.  We're scheduled to update Altarian Prophecy on the 22nd, and I believe that we are still on schedule for that.  We may need to do a smaller update before 1.2 to get this and a few other fixes out sooner.

1,822 views 22 replies
Reply #1 Top
Prepare for the accolades, Cari! :D
Reply #2 Top
Oh yeah... You go girl. :D
Reply #3 Top
Hommmmmmmm. We all bow down to your wisdom! :D
Reply #4 Top
Just a simple question :

I just had a problem with ships that don't appears on the building list (I mean they are here but no pictures :( ) and on the map : same thing, I see a blue light indicating that there is a ship there but no nice picture of it re :( .

Is that what you call the invisible ship bug ?

If it is so, I would stop trying to find out why it happened and should be able to find some sleep tonight,

Thanks for your answers.

BTW if it IS the invisible ship bug, is saving and reloading the game enough to solve the problem and continue enjoying the game ??
Reply #5 Top
Is that what you call the invisible ship bug ?
End of quote


It might be part of it, but what they really mean isa ships not appearing on the map, which this part at least can be fixed by saving and reloading.

~SDC~
Reply #6 Top
Not just ships, any graphics. Last night I had the graphic for class 5 planets not show up, for instance.

~SDC~
Reply #7 Top
A big virtual hug for the hard work :CONGRAT:
Reply #8 Top

Yeah, that does sound like the invisible ship bug.  Saving the game, shutting down Gal Civ, and restarting Gal Civ should fix the problem.

Reply #9 Top
The next update that you get (both Altarian Prophecy and Gal Civ 1.2) will have the fix for the invisible ship bug.
End of quote


Cari,
as the most vocal complaintaint about this bug I thank you for fixing it!! Your efforts, skill, and persistence are very, very much appreciated.
When/if you make it to Australia I would be honoured to be the first to supply you with chocolate and the beverage of your choice! (Assuming you like chocolate.)
Thank you.

:CONGRAT: :CONGRAT: :CONGRAT:
Reply #10 Top
Cari, you are a phenomenon. Everybody loves you. And you deserve every ounce of that love.

Keep up the great work!
Reply #11 Top
Oh, yes, I like chocolate. :) I'm just trying to cut down on the amounts of it that I consume.
Reply #12 Top
Oh, yes, I like chocolate.
End of quote


Great!! I will be delighted to supply appropriate quantities. (Check credit card limit as he speaks....)
Reply #13 Top
Wow! Nice bug hunt! It's tough chasing down the difficult ones, but soooo satisfying when you nail them. Keep up the great work, and have a few beers on me!

Bill :CONGRAT:
~SDC~
[Message Edited]
Reply #14 Top

Thank you all for your replies and of course a big smile to cari who will eliminate this bug soon.

BTW I am actually launching a full scale campaign of bug extermination in the game I'am currently playing
;).

Reply #15 Top
CaiElf,
Indeed, the process you went through to verify the problem was complex and attests to you astute comprehension of the guts (technical term LOL LOL ) of the game. But, I don't understand from what you said how sutting the game down ad restarting it made room for more graphics. From what you said, it sounds like a byte overflow on a counter that allocates so much space per count. For the shutdown to clean up this, it must mean that some of the counts are redundant and restarting only counts unique graphic types.

In any case, thank you very much for your hard work.

~SDC~
Reply #16 Top
Bless you, Cari! :) And all your kin and kith. :) I knew I made a good decision when I pre-ordered the expansion. Thank you for fixing this annoying bug and ending our long suffering. :HOT:

- Sirian
Reply #18 Top
Very well done :CONGRAT: :CONGRAT:

You really should enjoy the plaudit you get. You deserve it.

I know how hard it is to got through forreign code and I love all these "+ General code cleanup" in the history file. ;) Usually it's useless. But I hope it gives yourself a good feeling. And the latter really helps to hunt down these pesky bugs. Thus I do it all the time by myself, too.

I really would like to have more colleagues with the same dedication to their work.

By the way, do you already have a planned release date for Gal Civ 1.2 ?

Thank you very much for all
Reply #19 Top
Thanks for all your hard work and excellent product support! This has taken me off the fence--time to pre-order the expansion.
Reply #20 Top

No, I don't have a date for Gal Civ 1.2 yet.  Some of the stuff that will go into 1.2 also has to get into the Altarian Prophecy, so they should be done about the same time.

But, I don't understand from what you said how sutting the game down ad restarting it made room for more graphics
End of quote
Pretty much all the other systems are built off of the data manager, or use a instance (copy) of it.

Except for the pcx and tga files, all of the other graphics in the game are encoded into .mdl, .mtd, .tiles and .fnt files.  By encoded, I mean that the file contains both the graphical data and data that tells Gal Civ how to display it.  We call the files libraries and the sets of graphics within them books, and each book has at least one page which is a distinct image (although not necessarily unique).  So the game screen is a book, and the turn button is a page.  Each ship is a book.  We also call the pages of the books Sprites, because that's the term used by most of the game industry.

Now we have a Sprite Manager that takes care of all the sprites.  It loads them into memory, paints them, etc.  The Sprite Manager is a child of the Data Manager; ie it has all the same code as the Data Manager, plus more code that is specific to the Sprite Manager.  Most of the Managers are children of the Data Manager, because they need to handle data and the Data Manager gives them a consistent way to do it. Now that's great, because that means that we don't have to re-write code for every different system in the game.  Unfortunately, it means that if there's a bug in there, it'll be in all of them, and that can make finding and fixing the bug tricky.

So the data manager has a data container for the books called an array.  Arrays are like CD towers.  CD towers have a bunch of slots for CDs that will only fit CDs cases, not DVD cases.  You can pull a CD out from any slot in the tower without having to go through the entire tower to get to it. (That's called random access, by the way.)   And there's a set number of slots.  The data manager has a variable called ulNumOfBooks, which really should be named ulNumOfSlots or ulMaxNumOfBooks, because it's really the number of slots in the array, not the number of actual books in the array.  Anyway, deep in the guts of pear, that number is initially set to 256.  So when you click on the Gal Civ icon and it creates the window and it's all black, one of the things that it's doing is creating the array for 256 books. 

Now when Gal Civ goes to load a graphic, it checks the array to find an open slot for the book.  If it finds a spot, it puts the book in that slot, and when the painting code goes to paint that graphic, it gets the information from the book.  But it doesn't put anything in a slot until it goes to use that graphic, and it's supposed to remove it from the slot when that graphic is no longer being used.  For now, let's assume that it's doing what it's supposed to do, but it's still filling up all 256 slots. That's not too unlikely.  There's all the screens in Gal Civ, and most of the ship models have 11 different versions for the various races, and the logos for the stars, the stars and planets, etc. 

So as soon as the game went to load book #257, it was in trouble.  The person who wrote Pear was usually overzealous about putting in debug messages, and things that will bring the game to a halt if something bad is about to happen in memory (force asserts for those of you who know about programming).  Anyway, he missed this spot.  So the data manager would look for an open slot, and couldn't find one.  But it didn't have a debug message ("Hey, I need more memory here!") , it just quit trying to load it.  Hence the invisible ship or planet or whatever.

So I had to find all the places in the code where something was looking for an open slot for a book, and make it increase the number of books if it couldn't find an open slot.  This was simpler to fix than if it had been a byte overflow, which is what I was afraid it was. 

There is a byte overflow in the data manager, but so far it has only shown up in the string tables. I was able to fix that relatively easily by making a copy of the data manager, fixing just that copy, and making it the parent of the string tables instead of the old one.  But to fix it for the managers that deal with the graphics, like the sprite manager, I'd have to write a bunch of conversion routines so that we could still use the graphics that we have encoded.  Luckily for you guys, that bug didn't turn out to be the cause of the invisible ships.  With any luck, I won't have to fix the rest of the time bombs in there for Gal Civ 2, because Gal Civ 2 will be using 3D graphics so we'll be using differnet systems.

Reply #21 Top
Thanks for the explanation ;-)

Well done. Nice to see this issue finally solved.
Paul.

~SDC~
Reply #22 Top
CariElf,
Thank you for the detailed explanation. This is just another example of how helpful you are! :D I don't think any other person would have gone to the trouble to explain it in that detail.

cheers

~SDC~