SWY1985 / CivOne

An open source implementation of Sid Meier's Civilization.
http://www.civone.org/
Creative Commons Zero v1.0 Universal
243 stars 49 forks source link

`key '1699' was not present in the dictionary.` at IO/LZW.cs:line 124 #507

Open misterbeebee opened 3 years ago

misterbeebee commented 3 years ago

Built and ran on Mac OS X, using data files from an old Civilization installation.

Problem here:

Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Collections.Generic.KeyNotFoundException: The given key '1699' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at CivOne.IO.LZW.Decode(Byte[] input, Boolean clearEnd, Boolean flushDictionary, Int32 minBits, Int32 maxBits) in /Users/michaelroger/Documents/GitHub/CivOne/src/IO/LZW.cs:line 124
   at CivOne.Graphics.ImageFormats.PicFile.DecodePicture(Int32& index, UInt32 length) in /Users/michaelroger/Documents/GitHub/CivOne/src/Graphics/ImageFormats/PicFile.cs:line 124
   at CivOne.Graphics.ImageFormats.PicFile.ReadPictureX0(Int32& index) in /Users/michaelroger/Documents/GitHub/CivOne/src/Graphics/ImageFormats/PicFile.cs:line 140
   at CivOne.Graphics.ImageFormats.PicFile..ctor(String filename) in /Users/michaelroger/Documents/GitHub/CivOne/src/Graphics/ImageFormats/PicFile.cs:line 332
   at CivOne.Graphics.Resources.get_Item(String filename) in /Users/michaelroger/Documents/GitHub/CivOne/src/Graphics/Resources.cs:line 207
   at CivOne.Units.BaseUnit.SetIcon(Char page, Int32 col, Int32 row) in /Users/michaelroger/Documents/GitHub/CivOne/src/Units/BaseUnit.cs:line 761
   at CivOne.Units.Battleship..ctor() in /Users/michaelroger/Documents/GitHub/CivOne/src/Units/Battleship.cs:line 23
   --- End of inner exception stack trace ---

outer exception stack trace

   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
   at CivOne.Reflect.GetTypes[T]()+MoveNext() in /Users/michaelroger/Documents/GitHub/CivOne/src/Reflect.cs:line 75
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.GetEnumerator()+MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.OrderedEnumerable`1.TryGetFirst(Boolean& found)
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at CivOne.City..ctor(Byte owner) in /Users/michaelroger/Documents/GitHub/CivOne/src/City.cs:line 1106
   at CivOne.Game.AddCity(Player player, Int32 nameId, Int32 x, Int32 y) in /Users/michaelroger/Documents/GitHub/CivOne/src/Game.cs:line 260
   at CivOne.Tasks.Orders.CreateCity(Int32 nameId) in /Users/michaelroger/Documents/GitHub/CivOne/src/Tasks/Orders.cs:line 89
   at CivOne.Tasks.Orders.CreateCity(Player player, Int32 x, Int32 y) in /Users/michaelroger/Documents/GitHub/CivOne/src/Tasks/Orders.cs:line 121
   at CivOne.Tasks.Orders.CreateCity() in /Users/michaelroger/Documents/GitHub/CivOne/src/Tasks/Orders.cs:line 166
   at CivOne.Tasks.Orders.Run() in /Users/michaelroger/Documents/GitHub/CivOne/src/Tasks/Orders.cs:line 231
   at CivOne.GameTask.NextTask() in /Users/michaelroger/Documents/GitHub/CivOne/src/GameTask.cs:line 36
   at CivOne.GameTask.Finish(Object sender, EventArgs args) in /Users/michaelroger/Documents/GitHub/CivOne/src/GameTask.cs:line 73
   at CivOne.GameTask.EndTask() in /Users/michaelroger/Documents/GitHub/CivOne/src/GameTask.cs:line 86
   at CivOne.Tasks.Turn.Step() in /Users/michaelroger/Documents/GitHub/CivOne/src/Tasks/Turn.cs:line 33
   at CivOne.GameTask.Update() in /Users/michaelroger/Documents/GitHub/CivOne/src/GameTask.cs:line 42
   at CivOne.Screens.GamePlay..ctor() in /Users/michaelroger/Documents/GitHub/CivOne/src/Screens/GamePlay.cs:line 410
   at CivOne.Screens.NewGame.HasUpdate(UInt32 gameTick) in /Users/michaelroger/Documents/GitHub/CivOne/src/Screens/NewGame.cs:line 237
   at CivOne.Screens.BaseScreen.Update(UInt32 gameTick) in /Users/michaelroger/Documents/GitHub/CivOne/src/Screens/BaseScreen.cs:line 61
   at CivOne.RuntimeHandler.Update() in /Users/michaelroger/Documents/GitHub/CivOne/src/RuntimeHandler.cs:line 65
   at CivOne.RuntimeHandler.OnUpdate(Object sender, UpdateEventArgs args) in /Users/michaelroger/Documents/GitHub/CivOne/src/RuntimeHandler.cs:line 93
   at CivOne.Runtime.InvokeUpdate(UpdateEventArgs& args) in /Users/michaelroger/Documents/GitHub/CivOne/runtime/sdl/src/Runtime.cs:line 30
   at CivOne.GameWindow.Update(Object sender, EventArgs args) in /Users/michaelroger/Documents/GitHub/CivOne/runtime/sdl/src/GameWindow.cs:line 40
   at CivOne.SDL.Window.Run() in /Users/michaelroger/Documents/GitHub/CivOne/runtime/sdl/src/SDL/Window.cs:line 94
   at CivOne.Program.Main(String[] args) in /Users/michaelroger/Documents/GitHub/CivOne/runtime/sdl/src/Program.cs:line 86

For reference, the previous log output was:

Civilopedia: Preloading articles...
Warning: Character width larger than bytes per character. (ID: 95, Width: 9)
Loaded /Users/michaelroger/.local/share/CivOne/data/CITYPIX2.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/SP299.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/SP299.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/ICONPGD.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/ICONPGB.PIC
Game started
Checking data files...
- Done, all files exist
Changing window title changed from "CivOne" to "CivOne (press SHIFT+F1 to enter Setup)"
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH0.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH1.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/LOGO.PIC
Credits: "A MICROPROSE PRESENTATION"
Changing window title changed from "CivOne (press SHIFT+F1 to enter Setup)" to "CivOne"
Loaded /Users/michaelroger/.local/share/CivOne/data/SP257.PIC
Main Menu: EARTH
Map instance created
Map: Loading MAP.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/MAP.PIC
Map: Creating poles
Map: Placing goody huts
Map: Calculating land value
Map: Ready
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH2.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH3.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH4.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH5.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH6.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH7.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/BIRTH8.PIC
Intro: "In the beginning,"
Intro: "the Earth was without form,"
Intro: "and void."
Intro: "But the Sun shone upon the sleeping Earth"
Loaded /Users/michaelroger/.local/share/CivOne/data/DIFFS.PIC
Difficulty: Emperor (toughest)
Competition: 7 Civilizations
Loaded /Users/michaelroger/.local/share/CivOne/data/SLAM2.PIC
Tribe: Greek
Game instance created (difficulty: 4, competition: 7)
- Player 0 is Atilla of the Barbarians
- Player 1 is Caesar of the Romans
- Player 2 is Shaka of the Zulus
- Player 3 is Napoleon of the French
- Player 4 is Montezuma of the Aztecs
- Player 5 is Mao Tse Tung of the Chinese
- Player 6 is Mikos of the Greeks (human)
- Player 7 is M.Gandhi of the Indians
Adding starting units...
Calculate players handicap...
Apply players bonus...
Turn 0: 4000 BC
Mikos, you have risen
to become leader of the
Greeks. May your reign
be long and prosperous.
The Greeks have knowledge
of Irrigation, Mining,
and Roads.
misterbeebee commented 3 years ago

I added some logging on each call to PicFile constructor:

Civilopedia: Preloading articles...
Warning: Character width larger than bytes per character. (ID: 95, Width: 9)
New PicFile from filename: SP299
New PicFile from filename: CITYPIX2
Loaded /Users/michaelroger/.local/share/CivOne/data/CITYPIX2.PIC
New PicFile from filename: SP299
Loaded /Users/michaelroger/.local/share/CivOne/data/SP299.PIC
Loaded /Users/michaelroger/.local/share/CivOne/data/SP299.PIC
New PicFile from filename: ICONPGD
Loaded /Users/michaelroger/.local/share/CivOne/data/ICONPGD.PIC
New PicFile from filename: ICONPGB
Loaded /Users/michaelroger/.local/share/CivOne/data/ICONPGB.PIC
New PicFile from filename: ICONPGA

It appears to always fail to load the image ICONPGA.

Interestingly, this happens twice. The first time (before the UI starts), the exception is caught.

The second time, (when loading the main game screen for Turn 0, after the setup menus) the program crashes.

Coincidentally(?), ICONPGA is one of the few ICONPG files with both a .PAL file and a .PIC file.

I have a mild suspicion that CivOne is failing to decode the first .PIC file that has a .PAL (palette) co-file.

misterbeebee commented 3 years ago

By removing ICONPGA.PIC and copyingICONPGB.PIC in its place, I am able to start playing the game.

Something must be wrong with my ICONPGA.PIC or with the way CivOne decodes that particular file in my particular version of the game.

I'm not sure which version of the game I have, but my data files are all dated "Dec 17 1991", except for PRODUCT.TXT dated "Jan 5 1992".