(possible) new crash related to morale and huge empires

This forum contains threads from main General Chat forum older than 3 months.

Moderator: thunderchero

User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

(possible) new crash related to morale and huge empires

Post by henka »

Some days ago while playing UDM 3.0.1 with large maps, i experienced a crash (CTD) when the game processed the next turn. The crash log stated the following lines:

Version Under Test: 72
File: ..\..\source\game\economy\morale.c, Line: 102, Illegal Morale value
Initialize State: 31
Player Empire: 1 Starting Seed: 1256755788
Galaxy shape: 1 Galaxy Size: 2
Turn State: 20
Turn Number: 677

After some investigation i came to the conclusion, that the problem is probably caused by the calculation of the average morale, which is displayed in the intel empire screen.
My empire consists of about 170 systems and the sum of all morale values was 32733. Now every morale raising action lead to a crash. Maybe for the sum calculation a signed 2 byte value is used, which can only hold a maximum positiv value of 32767. I estimated the total moral boost of the next colonization to be between 138 and 207, which would cause the signed byte to overflow, resulting in a negativ value.

I think the ship build cost display bug had the same cause. At least i can explain the values for the problem statet at viewtopic.php?name=Forums&file=viewtopi ... ight=#9132. Because -29729 is exactly the result what you get, when you add 3040 (the difference between the buildcost and 32767) to 32767 as a signed short.

If my conclusion is correct, the problem won't appear as long as your empire consists of 168 systems or less.

If someone wants to take a closer look at the problem, i can provide more specific information along with savegames to provoke this crash.
Last edited by henka on Sat Dec 19, 2009 6:00 am, edited 5 times in total.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7934
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Post by thunderchero »

henka,

I would say your conclusion is correct.

I am not sure how easy this will be to fix, I have already seen a couple errors like this one related to large maps.

I am always interested in looking at saved game errors like this. You can upload it to here.

http://www.4shared.com/dir/2718631/36f4 ... aring.html

thunderchero
User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

Post by henka »

i have uploaded a savegame under savegame for morale overflow bug.zip
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7934
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Post by thunderchero »

henka,

I took a look at your save, wow 185 systems

I would not expect a fix quickly. But I will add error to list of known bugs along with the system display error (over 99)

thunderchero
User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

Post by henka »

I think this was the first time i played beyond 500 rounds.
Take it as a compliment. It is your great mod which keeps me playing on and on and on :D

In the meantime i will help me out with some morale lowering actions.
As i'am a bit familiar with reverse engineering, i know what effort it is to track these bugs and correct them.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7934
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Post by thunderchero »

I did do a little more testing on your saved game.

first lowered morale of all systems by declaring war on every major. after turning off (powered down) all structures. I took sol from 195 to 174. then colonized all systems in top left (I think 6-7 systems) next turn went thougn no problem.

So it is not total systems

thunderchero
User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

Post by henka »

I'll check these findings.

The tests which led me to the conclusion that this could be related to the sum of morale values was the following

round 678: colonized Tribble
round 679: crash when tryin to colonize
round 680: crash when tryin to colonize
round 681: crash when tryin to colonize
round 682: crash when tryin to colonize
round 683: colonized Kavaria
round 684: crash when tryin to colonize
round 685: crash when tryin to colonize
round 686: crash when tryin to colonize
round 687: crash when tryin to colonize
round 688: crash when tryin to colonize
round 689: colonized Pelleus

so the number of rounds between 2 colonizations needed increases. I'll try to validate this some turns further.
User avatar
Tethys
Past Administrator
Past Administrator
Posts: 2404
Joined: Fri Jul 18, 2008 2:00 am
Location: Your mom's bed ;)
Contact:

Post by Tethys »

sounds like it could be related to the ship cost display bug, perhaps increasing to FF FF (or FF FF FF FF) in hex (if you know where it is) would do the trick?

could be hard to find tho.. but i do remember ships being set to a NEGATIVE (or otherwise invalid) display value after reaching a certain cost (around 30000something)
Not for the weak of heart...
Galaxies MOD v0.4.0 <--- GALM/Galaxies Mod latest version
User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

Post by henka »

Tethys wrote:but i do remember ships being set to a NEGATIVE (or otherwise invalid) display value after reaching a certain cost (around 30000something)
I remembered this bug too, as i investigated this problem. I think the value was 32767 (2^15-1) like i think it is in this case. This is the maximal positiv value, a signed short is able to represent. If you would add 1 to this value, the result would be -32768. I edited my first posting to better reflect this issue.
User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

Post by henka »

thunderchero wrote:I did do a little more testing on your saved game.

first lowered morale of all systems by declaring war on every major. after turning off (powered down) all structures. I took sol from 195 to 174. then colonized all systems in top left (I think 6-7 systems) next turn went thougn no problem.

So it is not total systems

thunderchero
I repeated these steps with the same results. Colonizing up to 7 systems went through with no problem. But as i tried to colonize 8 systems, the game crashed. I will calculate the sum of all morale values again and post it later. Maybe your conclusion was a bit rash, we'll see.
User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

Post by henka »

So, i calculated the total sum of morale values of all my systems after the mentioned steps. It is 32277 and so it is not surprising that the game didn't crash because it is 490 below the signed short maxvalue of 32767.

Now lets estimate the extra total moral difference when colonizing 8 instead of 7 planets:
Before colonization there were 174 systems. When i colonized 7 systems, sol was back at 195 and the second best morale was 188. So the colonization of an 8th. system will only affect 173 systems. 173*3 = 519 which is enough to let the signed short overflow and get negative. So i think i can leave the extra morale from that 8th new systems out of my calculation :)

If someone can show me a savegame where the total sum of moral values of all your systems is greater than 32767, i have to reconsider my theory, but till now the facts don't show a contradiction to this theory.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7934
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Post by thunderchero »

henka,

I do not think a total is kept in saved game (at least that I can find).

I think the trek.exe calulates this from each systems morale. When adding them up. It get the - value and throws error before calculation is complete.

The error is located at 0x64fc0 in trek.exe But I am no good at reading what is going on.

thunderchero
User avatar
Spocks-cuddly-tribble
Code Master
Code Master
Posts: 1926
Joined: Sun Apr 27, 2008 2:00 am

Re: (possible) new crash related to morale and huge empires

Post by Spocks-cuddly-tribble »

henka wrote:the problem is probably caused by the calculation of the average morale, which is displayed in the intel empire screen (...) for the sum calculation a signed 2 byte value is used, which can only hold a maximum positiv value of 32767.
Well, then let’s fix this nasty overflow:


46118C add di, [eax+44h] // at 0x6058C change 66 to 90

4611C2 movsx edx, di // at 0x605C2 change 0F BF to 90 8B


I hope tomorrow I can free up the online-time to hear if this works (and also have a word with the admin, for one reason or other).

henka wrote:round 678: colonized Tribble
Get the hell out of my system(your stock of food can stay). :P
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
User avatar
thunderchero
Site Administrator aka Fleet Admiral
Site  Administrator aka Fleet Admiral
Posts: 7934
Joined: Fri Apr 25, 2008 2:00 am
Location: On a three month training mission, in command of the USS Valiant.

Post by thunderchero »

Spocks-cuddly-tribble,

sorry, in my tests with henka save, same error message, but CTD when game loads.

thunderchero
User avatar
henka
Cadet 4th Year
Cadet 4th Year
Posts: 17
Joined: Fri Nov 13, 2009 3:00 am
Location: Germany

Re: (possible) new crash related to morale and huge empires

Post by henka »

thunderchero wrote:henka,

I do not think a total is kept in saved game (at least that I can find).

I think the trek.exe calulates this from each systems morale.
thunderchero
Ah, then i have mistaken you, i'am sorry for that. I assumed that this bug is located in trek.exe, too. It would not make much sense to store such an intermediate value in a save game.
Spocks-cuddly-tribble wrote:
henka wrote:the problem is probably caused by the calculation of the average morale, which is displayed in the intel empire screen (...) for the sum calculation a signed 2 byte value is used, which can only hold a maximum positiv value of 32767.
Well, then let’s fix this nasty overflow:


46118C add di, [eax+44h] // at 0x6058C change 66 to 90

4611C2 movsx edx, di // at 0x605C2 change 0F BF to 90 8B


I hope tomorrow I can free up the online-time to hear if this works (and also have a word with the admin, for one reason or other).
With these modifications the game crashes when loading the savegame. The crash log is nearly the same. Only the lines for Turnstate and Turnnumber are missing, i assume this is due to the load procedure.

Creating a new game works fine.
Spocks-cuddly-tribble wrote:
henka wrote:round 678: colonized Tribble
Get the hell out of my system(your stock of food can stay). :P
I will take care of these cute little cuddly pets :D
Post Reply

Return to “General Chat Archive”