Morale overflow over 32767 bug (fix)

Morale overflow over 32767 bug (fix); support/discussion/questions

Moderator: thunderchero

Post Reply
User avatar
Code Master
Code Master
Posts: 853
Joined: Sun Apr 27, 2008 2:00 am

Morale overflow over 32767 bug (fix)

Post by Spocks-cuddly-tribble »

A very good error analysis by henka and the answer to the problem:

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

File: ..\..\source\game\economy\morale.c, Line: 102, Illegal Morale value

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.

If my conclusion is correct, the problem won't appear as long as your empire consists of 168 systems or less.
This should be fully operative: :)

Code: Select all

trek.exe at 0x60581

8B 14 24 8D 83 40 02 00 00 01 D0 66 03 78 44
8D 83 40 02 00 00 03 04 24 0F B7 40 44 03 F8

AND at 0x605C2 change: 0F BF to: 90 8B

asm 461181:
lea     eax, [ebx+240h]
add     eax, [esp]
movzx   eax, word ptr [eax+44h]
add     edi, eax

asm 4611C2: 
mov   edx, edi
I don't know how many bugs is too many but that point is reached somewhere before however many in BotF is.
Post Reply

Return to “Morale overflow over 32767 bug (fix)”