Help Please: CTD happens on the same turn.

KJ Jansson

Prince
Joined
Oct 7, 2008
Messages
509
Help Please: CTD happens on the same turn.

Could somebody help with my problem?

Here some details.

I create a new "1492: Global Colonization" mod for Colonization where some features of Civilization will be included. Some screens and details are available here.

At the moment I included a number of new resources in the mod. Instead of 16 resources in the original version of CivIVCol (1.01f) I have 30 resources.

I changed only 4 files in SDK: CvCityAI.cpp, CvEnums.h, CvPlayerAI.cpp and CyEnumInterface.cpp. Here I added new resources, then I compiled a new CvGameCoreDLL.dll by using CodeBlocks.

For instance in CyEnumsInterface.cpp were added:
Spoiler :

Code:
	python::enum_<YieldTypes>("YieldTypes")
		.value("NO_YIELD", NO_YIELD)
		.value("YIELD_FOOD", YIELD_FOOD)
		.value("YIELD_LUMBER", YIELD_LUMBER)
		.value("YIELD_STONE", YIELD_STONE)											//KJ RESOURCES
		.value("YIELD_ORE", YIELD_ORE)		
		.value("YIELD_SILVER", YIELD_SILVER)
		.value("YIELD_GOLD", YIELD_GOLD)											//MORE_YIELD_TYPES		05/05/09		Aymerick
		.value("YIELD_GEMS", YIELD_GEMS)											//KJ RESOURCES
		.value("YIELD_COTTON", YIELD_COTTON)
		.value("YIELD_FUR", YIELD_FUR)
		.value("YIELD_SUGAR", YIELD_SUGAR)
		.value("YIELD_TOBACCO", YIELD_TOBACCO)		
		.value("YIELD_DRUGS", YIELD_DRUGS)											//KJ RESOURCES
		.value("YIELD_INDIGO", YIELD_INDIGO)										//MORE_YIELD_TYPES		05/05/09		Aymerick
		.value("YIELD_INCENSE", YIELD_INCENSE)										//KJ RESOURCES
		.value("YIELD_COFFEE", YIELD_COFFEE)										//MORE_YIELD_TYPES		05/05/09		Aymerick		
		.value("YIELD_COCOA", YIELD_COCOA)											//KJ RESOURCES
		.value("YIELD_TEA", YIELD_TEA)												//KJ RESOURCES
		.value("YIELD_SPICES", YIELD_SPICES)										//KJ RESOURCES
		.value("YIELD_IVORY", YIELD_IVORY)											//KJ RESOURCES		
		.value("YIELD_EBONY", YIELD_EBONY)											//KJ RESOURCES
		.value("YIELD_CLOTH", YIELD_CLOTH)
		.value("YIELD_COATS", YIELD_COATS)
		.value("YIELD_RUM", YIELD_RUM)
		.value("YIELD_CIGARS", YIELD_CIGARS)
		.value("YIELD_TOOLS", YIELD_TOOLS)
		.value("YIELD_MUSKETS", YIELD_MUSKETS)
		.value("YIELD_HORSES", YIELD_HORSES)
		.value("YIELD_TRADE_GOODS", YIELD_TRADE_GOODS)
		.value("YIELD_ARTISANS_PRODUCTS", YIELD_ARTISANS_PRODUCTS)					//KJ RESOURCES		
		.value("YIELD_SLAVES", YIELD_SLAVES)										//KJ RESOURCES		
		.value("YIELD_HAMMERS", YIELD_HAMMERS)
		.value("YIELD_BELLS", YIELD_BELLS)
		.value("YIELD_CROSSES", YIELD_CROSSES)
		.value("YIELD_EDUCATION", YIELD_EDUCATION)
		.value("NUM_YIELD_TYPES", NUM_YIELD_TYPES)
		;

All new resources were described in xml files: CIV4YieldInfos.xml, CIV4BonusInfos.xml, CIVBuildinInfos, xml, CIV4UnitClassInfos.xml, CIV4UnitInfos.xml, etc., plus a number of corresponding ART and TEXT files.

Both Gamefonts files were corrected.

On this stage I could start the mod without errors. I expected that no critical errors are present because at least 50 turns the game runs perfectly and I had no errors at all.

However yesterday I run my mod a little bit more turns and found that last successful turn was 52. Each time turn 53 give me the same error and crash to desktop independently on map (type or size), game speed, used nations, etc.

All the time the report message was the same

AppName: colonization.exe AppVer: 1.0.0.1 ModName: cvgamecoredll.dll
ModVer: 0.0.0.0 Offset: 0001cfb0

I follow to this advice

Make sure this line is changed in your ini

; Create a dump file if the application crashes
GenerateCrashDumps = 1

and created Colonization.exe.dmp file.

Then I installed Debugging Tools for Windows as recommended in this message:

If it is popping up the screen asking if you want a full or normal crashdump, then get WinDbg and your problems MAY resolve a bit quicker. Sometimes this will manage to point you right to the line of the DLL causing you problems.

Install that, get a crash to happen, then load WinDbg, hit CTRL+D, find the crashdump, and then type "!analyze -v" and it should inform you of what it knows.

I follow to recommendations and here my error log from WinDbg:

Code:
Microsoft (R) Windows Debugger Version 6.11.0001.404 X86
Copyright (c) Microsoft Corporation. All rights reserved.

Loading Dump File [D:\Debugging Tools for Windows\Colonization.exe.dmp]
User Mini Dump File with Full Memory: Only application data is available

Symbol search path is: C:\WINDOWS\Symbols
Executable search path is: 
Windows XP Version 2600 (Service Pack 2) MP (2 procs) Free x86 compatible
Product: WinNt, suite: SingleUserTS
Machine Name:
Debug session time: Sun Nov 22 23:56:38.000 2009 (GMT+2)
System Uptime: 0 days 14:35:05.342
Process Uptime: 0 days 0:04:57.000
................................................................
.........
This dump file has an exception of interest stored in it.
The stored exception information can be accessed via .ecxr.
(1204.1208): Access violation - code c0000005 (first/second chance not available)
eax=06d00000 ebx=1bd3c270 ecx=00000007 edx=7c90eb94 esi=1bd3c248 edi=1bd3c2a0
eip=7c90eb94 esp=0012e31c ebp=0012e32c iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
ntdll!KiFastSystemCallRet:
7c90eb94 c3              ret
0:000> !analyze -v
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************

*** ERROR: Symbol file could not be found.  Defaulted to export symbols for Colonization.exe - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for zlib1.dll - 
*** WARNING: Unable to verify checksum for hapdbg.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for hapdbg.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for d3dx9_33.dll - 
*** WARNING: Unable to verify checksum for msseax.flt
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for msseax.flt - 
*** WARNING: Unable to verify checksum for msssrs.flt
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for msssrs.flt - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for d3dx9_31.dll - 
*** WARNING: Unable to verify checksum for boost_python-vc71-mt-1_32.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for boost_python-vc71-mt-1_32.dll - 
*** WARNING: Unable to verify checksum for binkw32.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for binkw32.dll - 
*** WARNING: Unable to verify checksum for python24.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for python24.dll - 
*** WARNING: Unable to verify checksum for LvHook.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for LvHook.dll - 
*** WARNING: Unable to verify checksum for Mss32.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for Mss32.dll - 
*** WARNING: Unable to verify checksum for mssds3d.flt
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for mssds3d.flt - 
*** WARNING: Unable to verify checksum for mssdolby.flt
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for mssdolby.flt - 
*** WARNING: Unable to verify checksum for mssdsp.flt
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for mssdsp.flt - 
*** WARNING: Unable to verify checksum for mssvoice.asi
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for mssvoice.asi - 
*** WARNING: Unable to verify checksum for mssmp3.asi
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for mssmp3.asi - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for asOEHook.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for ccL40.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for PSAPI.DLL - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for clbcatq.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for ole32.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for gdi32.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for shlwapi.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for msvcr71.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for msvcp71.dll - 
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for shell32.dll - 
*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: IMAGE_NT_HEADERS32                            ***
***                                                                   ***
*************************************************************************
Failed calling InternetOpenUrl, GLE=12007
*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************
*************************************************************************
***                                                                   ***
***                                                                   ***
***    Your debugger is not using the correct symbols                 ***
***                                                                   ***
***    In order for this command to work properly, your symbol path   ***
***    must point to .pdb files that have full type information.      ***
***                                                                   ***
***    Certain .pdb files (such as the public OS symbols) do not      ***
***    contain the required information.  Contact the group that      ***
***    provided you with these symbols if you need this command to    ***
***    work.                                                          ***
***                                                                   ***
***    Type referenced: kernel32!pNlsUserInfo                         ***
***                                                                   ***
*************************************************************************

FAULTING_IP: 
CvGameCoreDLL!CvCity::getMaxYieldCapacity+30
03ebcfb0 8b8b84000000    mov     ecx,dword ptr [ebx+84h]

EXCEPTION_RECORD:  ffffffff -- (.exr 0xffffffffffffffff)
ExceptionAddress: 03ebcfb0 (CvGameCoreDLL!CvCity::getMaxYieldCapacity+0x00000030)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000000
   Parameter[1]: 00000084
Attempt to read from address 00000084

PROCESS_NAME:  Colonization.exe

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at "0x%08lx" referenced memory at "0x%08lx". The memory could not be "%s".

EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at "0x%08lx" referenced memory at "0x%08lx". The memory could not be "%s".

EXCEPTION_PARAMETER1:  00000000

EXCEPTION_PARAMETER2:  00000084

READ_ADDRESS:  00000084 

FOLLOWUP_IP: 
CvGameCoreDLL!CvCity::getMaxYieldCapacity+30
03ebcfb0 8b8b84000000    mov     ecx,dword ptr [ebx+84h]

NTGLOBALFLAG:  0

APPLICATION_VERIFIER_FLAGS:  0

FAULTING_THREAD:  00001208

BUGCHECK_STR:  APPLICATION_FAULT_NULL_CLASS_PTR_DEREFERENCE_INVALID_POINTER_READ

PRIMARY_PROBLEM_CLASS:  NULL_CLASS_PTR_DEREFERENCE

DEFAULT_BUCKET_ID:  NULL_CLASS_PTR_DEREFERENCE

LAST_CONTROL_TRANSFER:  from 03fe477b to 03ebcfb0

STACK_TEXT:  
0012f44c 03fe477b 00000000 02044128 00af3c44 CvGameCoreDLL!CvCity::getMaxYieldCapacity+0x30
0012f51c 03fe9033 02044128 03fcdd93 00000001 CvGameCoreDLL!CvPlayerAI::AI_doTradeRoutes+0x16b
0012f524 03fcdd93 00000001 02044128 00000000 CvGameCoreDLL!CvPlayerAI::AI_doTurnPost+0x13
0012f54c 03fce21c 00000004 02044128 00af3c44 CvGameCoreDLL!CvPlayer::doTurn+0x313
0012fd98 03fce437 00000000 00000001 03f0d88d CvGameCoreDLL!CvPlayer::setTurnActive+0x44c
0012fda4 03f0d88d 00000000 00bec514 02115180 CvGameCoreDLL!CvPlayer::setAutoMoves+0x67
0012fdd8 03f120aa 000ce34f 0012ff08 03f4d170 CvGameCoreDLL!CvGame::updateMoves+0x13d
0012fe70 00412d54 77d493e9 003e7028 00000000 CvGameCoreDLL!CvGame::update+0x31a
WARNING: Stack unwind information not available. Following frames may be wrong.
0012fe88 7c82307d 0012fed0 7c34240d 7c37a3a8 Colonization+0x12d54
0012fea0 0068a517 003e7248 003e7254 0012fe01 kernel32!SetCurrentDirectoryA+0x2a
0012febc 0040f5bd 7c80b529 003e7028 00000000 Colonization+0x28a517
003e7254 6d75636f 73746e65 646e6120 74655320 Colonization+0xf5bd
003e7258 73746e65 646e6120 74655320 676e6974 0x6d75636f
003e725c 646e6120 74655320 676e6974 50485c73 0x73746e65
003e7260 74655320 676e6974 50485c73 6d64415f 0x646e6120
003e7264 676e6974 50485c73 6d64415f 73696e69 0x74655320
003e7268 50485c73 6d64415f 73696e69 74617274 0x676e6974
003e726c 6d64415f 73696e69 74617274 4c5c726f 0x50485c73
003e7270 73696e69 74617274 4c5c726f 6c61636f 0x6d64415f
003e7274 74617274 4c5c726f 6c61636f 74655320 0x73696e69
003e7278 4c5c726f 6c61636f 74655320 676e6974 0x74617274
003e727c 6c61636f 74655320 676e6974 70415c73 0x4c5c726f
003e7280 74655320 676e6974 70415c73 63696c70 0x6c61636f
003e7284 676e6974 70415c73 63696c70 6f697461 0x74655320
003e7288 70415c73 63696c70 6f697461 6144206e 0x676e6974
003e728c 63696c70 6f697461 6144206e 4d5c6174 0x70415c73
003e7290 6f697461 6144206e 4d5c6174 61472079 0x63696c70
003e7294 6144206e 4d5c6174 61472079 5c73656d 0x6f697461
003e7298 4d5c6174 61472079 5c73656d 20646953 0x6144206e
003e729c 61472079 5c73656d 20646953 6569654d 0x4d5c6174
003e72a0 5c73656d 20646953 6569654d 20732772 0x61472079
003e72a4 20646953 6569654d 20732772 69766943 0x5c73656d
003e72a8 6569654d 20732772 69766943 617a696c 0x20646953
003e72ac 20732772 69766943 617a696c 6e6f6974 0x6569654d
003e72b0 69766943 617a696c 6e6f6974 20564920 0x20732772
003e72b4 617a696c 6e6f6974 20564920 6f6c6f43 0x69766943
003e72b8 6e6f6974 20564920 6f6c6f43 617a696e 0x617a696c
003e72bc 20564920 6f6c6f43 617a696e 6e6f6974 0x6e6f6974
003e72c0 6f6c6f43 617a696e 6e6f6974 0000005c 0x20564920
003e72c4 617a696e 6e6f6974 0000005c 00000000 0x6f6c6f43
003e72c8 6e6f6974 0000005c 00000000 00000000 0x617a696e
003e72cc 00000000 00000000 00000000 00000000 0x6e6f6974


STACK_COMMAND:  ~0s; .ecxr ; kb

SYMBOL_STACK_INDEX:  0

SYMBOL_NAME:  CvGameCoreDLL!CvCity::getMaxYieldCapacity+30

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: CvGameCoreDLL

IMAGE_NAME:  CvGameCoreDLL.dll

DEBUG_FLR_IMAGE_TIMESTAMP:  4ae5c857

FAILURE_BUCKET_ID:  NULL_CLASS_PTR_DEREFERENCE_c0000005_CvGameCoreDLL.dll!CvCity::getMaxYieldCapacity

BUCKET_ID:  APPLICATION_FAULT_NULL_CLASS_PTR_DEREFERENCE_INVALID_POINTER_READ_CvGameCoreDLL!CvCity::getMaxYieldCapacity+30

WATSON_STAGEONE_URL:  http://watson.microsoft.com/StageOne/Colonization_exe/1_0_0_1/49a88196/CvGameCoreDLL_dll/0_0_0_0/4ae5c857/c0000005/0001cfb0.htm?Retriage=1

Followup: MachineOwner

I'm not a professional programmer and here I understand just two moments.

1. WinDbg found absolutely correctly the error place. Compare


in WinDbg report with error message from game report after CTD

AppName: colonization.exe AppVer: 1.0.0.1 ModName: cvgamecoredll.dll
ModVer: 0.0.0.0 Offset: 0001cfb0

The same offset 0001cfb0.

2. WinDbg found the place where the error happens

Code:
FAILURE_BUCKET_ID:  NULL_CLASS_PTR_DEREFERENCE_c0000005_CvGameCoreDLL.dll!CvCity::getMaxYieldCapacity

namely

CvCity::getMaxYieldCapacity

Notepad++ show me that CvCity::getMaxYieldCapacity is present in game source codes only in one place in CvCity.cpp:

Code:
int CvCity::getMaxYieldCapacity() const
{
	int iCapacity = GC.getGameINLINE().getCargoYieldCapacity();

	for (int iBuildingClass = 0; iBuildingClass < GC.getNumBuildingClassInfos(); ++iBuildingClass)
	{
		BuildingTypes eBuilding = (BuildingTypes) GC.getCivilizationInfo(getCivilizationType()).getCivilizationBuildings(iBuildingClass);
		if (eBuilding != NO_BUILDING)
		{
			if (isHasBuilding(eBuilding))
			{
				iCapacity += GC.getBuildingInfo(eBuilding).getYieldStorage() * GC.getGameSpeedInfo(GC.getGameINLINE().getGameSpeedType()).getStoragePercent() / 100;
			}
		}
	}

	return iCapacity;
}

Here I made no changes at all.

However int CvCity::getMaxYieldCapacity() const somehow (?) related to the MaxYieldCapacity and as I mentioned above 14 (30-16) new resources are included in the mod.

"MaxYieldCapacity" found 25 times in 9 files.

Well, that else? :confused: Now I reached my final point. I absolutely have no ideas what I have to do next and how to fix the error.

Could somebody give me some advices what I have do next and how to fix the crash? Thank you very much in advance.

P.S.
I have rather low knowledge in programming and all steps I made before are very simple.
Due to some reasons I have only CodeBlocks program to compile CvGameCoreDLL.dll

P.P.S.
Please, don't move my message on Colonization section because my problem is common for both CivilizationIV and CivIVColonization and the special "Civ4 - SDK/Python" section there is only here.
 
After couple days of very intensive search I found at least and fixed a fragment in the source codes that gives me CTD.

This thread could be closed.
 
What has been the problem?

I compiled a debug CvGameCoreDLL.dll by using CodeBlocks and found that error messages of two types (in various number and in various combination) are observed immediately before CTD:

Code:
1 Assert Failed

File:  CvCity.cpp
Line:  4145
Expression:  iValue >= 0 || eYield == YIELD_FOOD
Message:

In CvCity.cpp:

Spoiler :
Code:
void CvCity::setYieldStored(YieldTypes eYield, int iValue)
{
	FAssertMsg(eYield >= 0, "eYield expected to be >= 0");
	FAssertMsg(eYield < NUM_YIELD_TYPES	, "eYield expected to be < NUM_YIELD_TYPES");
(4145)	FAssert(iValue >= 0 || eYield == YIELD_FOOD);

	int iChange = iValue - getYieldStored(eYield);
	if (iChange != 0)
	{
		m_aiYieldStored[eYield] = iValue;

		if (!AI_isWorkforceHack())
		{
			checkCompletedBuilds(eYield, iChange);
		}

		GET_PLAYER(getOwnerINLINE()).changePower(GC.getYieldInfo(eYield).getPowerValue() * iChange);
		GET_PLAYER(getOwnerINLINE()).changeAssets(GC.getYieldInfo(eYield).getAssetValue() * iChange);
		area()->changePower(getOwnerINLINE(), GC.getYieldInfo(eYield).getPowerValue() * iChange);

		if (getTeam() == GC.getGameINLINE().getActiveTeam())
		{
			setBillboardDirty(true);

			if (getOwnerINLINE() == GC.getGameINLINE().getActivePlayer())
			{
				gDLL->getInterfaceIFace()->setDirty(ResourceTable_DIRTY_BIT, true);
				gDLL->getInterfaceIFace()->setDirty(CitizenButtons_DIRTY_BIT, true);
				gDLL->getInterfaceIFace()->setDirty(CityScreen_DIRTY_BIT, true);
			}
		}
	}
}
Code:
2. Assert Failed

File:  CvCity.cpp
Line:  4288
Expression:  (iYield == YIELD_FOOD) || (aiYields[iYield] >= 0)
Message:

In CvCity.cpp:

Spoiler :
Code:
void CvCity::calculateNetYields(int aiYields[NUM_YIELD_TYPES], int* aiProducedYields, int* aiConsumedYields, bool bPrintWarning) const
{
	PROFILE_FUNC();
	
	int aiConsumed[NUM_YIELD_TYPES];
	int aiProduced[NUM_YIELD_TYPES];
	if (aiProducedYields == NULL)
	{
		aiProducedYields = aiProduced;
	}
	if (aiConsumedYields == NULL)
	{
		aiConsumedYields = aiConsumed;
	}

	for (int iYield = 0; iYield < NUM_YIELD_TYPES; ++iYield)
	{
		YieldTypes eYield = (YieldTypes) iYield;
		aiConsumedYields[iYield] = getRawYieldConsumed(eYield);
		aiProducedYields[iYield] = getBaseRawYieldProduced(eYield);
		aiYields[iYield] = getYieldStored(eYield) - aiConsumedYields[iYield] + aiProducedYields[iYield] * getBaseYieldRateModifier(eYield) / 100;
	}

	std::set<ProfessionTypes> setUnsatisfiedProfessions;

	if (!isOccupation())
	{
		std::vector<int> aiYieldsAvailable;
		for (uint i = 0; i < m_aPopulationUnits.size(); ++i)
		{
			CvUnit* pUnit = m_aPopulationUnits[i];
			if (pUnit->getProfession() != NO_PROFESSION)
			{
				aiYieldsAvailable.push_back(getProfessionInput(pUnit->getProfession(), pUnit));
			}
			else
			{
				aiYieldsAvailable.push_back(0);
			}
		}

		for (uint i = 0; i < m_aPopulationUnits.size(); ++i)
		{
			bool bFound = false;
			for (int iUnitIndex = 0; iUnitIndex < (int)m_aPopulationUnits.size(); ++iUnitIndex)
			{
				CvUnit* pUnit = m_aPopulationUnits[iUnitIndex];

				if (aiYieldsAvailable[iUnitIndex] > 0)
				{
					CvProfessionInfo& kProfession = GC.getProfessionInfo(pUnit->getProfession());

					YieldTypes eYieldConsumed = (YieldTypes) kProfession.getYieldConsumed();

					if (eYieldConsumed != NO_YIELD)
					{
						int iYieldStored = aiYields[eYieldConsumed];
						if (iYieldStored < 0)
						{
							if (bPrintWarning)
							{
								setUnsatisfiedProfessions.insert(pUnit->getProfession());
							}

							bFound = true;
							YieldTypes eYieldProduced = (YieldTypes) kProfession.getYieldProduced();
							if (NO_YIELD != eYieldProduced)
							{
								int iDeficit = std::min(-iYieldStored, aiYieldsAvailable[iUnitIndex]);
								aiYieldsAvailable[iUnitIndex] -= iDeficit;

								aiConsumedYields[eYieldConsumed] -= iDeficit;
								aiProducedYields[eYieldProduced] -= iDeficit;

								aiYields[eYieldProduced] = getYieldStored(eYieldProduced) - aiConsumedYields[eYieldProduced] + aiProducedYields[eYieldProduced] * getBaseYieldRateModifier(eYieldProduced) / 100;
								aiYields[eYieldConsumed] = getYieldStored(eYieldConsumed) - aiConsumedYields[eYieldConsumed] + aiProducedYields[eYieldConsumed] * getBaseYieldRateModifier(eYieldConsumed) / 100;
							}
							else
							{
								FAssertMsg(false, "Could not find matching production for negative yield rate.");
							}
						}
					}
				}
			}

			if(!bFound)
			{
				break;
			}
		}
	}

	for (int iYield = 0; iYield < NUM_YIELD_TYPES; ++iYield)
	{
(4288)		FAssert((iYield == YIELD_FOOD) || (aiYields[iYield] >= 0));
		aiYields[iYield] -= getYieldStored((YieldTypes) iYield);
	}

	// Immigration
	int iImmigration = 0;
	YieldTypes eImmigrationYield = GET_PLAYER(getOwnerINLINE()).getImmigrationConversion();
	if (eImmigrationYield != YIELD_CROSSES)
	{
		aiYields[eImmigrationYield] += aiYields[YIELD_CROSSES];
	}

	for (std::set<ProfessionTypes>::iterator it = setUnsatisfiedProfessions.begin(); it != setUnsatisfiedProfessions.end(); ++it)
	{
		CvProfessionInfo& kProfession = GC.getProfessionInfo(*it);
		YieldTypes eYieldConsumed = (YieldTypes) kProfession.getYieldConsumed();
		YieldTypes eYieldProduced = (YieldTypes) kProfession.getYieldProduced();

		if (eYieldConsumed != NO_YIELD)
		{
			CvWString szBuffer = gDLL->getText("TXT_KEY_NO_RAW", getNameKey(),GC.getYieldInfo(eYieldConsumed).getChar(), GC.getYieldInfo(eYieldProduced).getChar());
			gDLL->getInterfaceIFace()->addMessage(getOwnerINLINE(), false, GC.getEVENT_MESSAGE_TIME(), szBuffer, "AS2D_DEAL_CANCELLED", MESSAGE_TYPE_MINOR_EVENT, GC.getYieldInfo(eYieldConsumed).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), getX_INLINE(), getY_INLINE(), true, true);
		}
	}
}
Well, I don't know, but maybe for professional programmers all is clear from these lines, however, I spend couple days to find logically the problem.

The problem was in this section of CvPlayerAI.cpp.

I had such distribution of resources (Yields) in the beginning

Spoiler :
Code:
bool CvPlayerAI::AI_isYieldFinalProduct(YieldTypes eYield) const
{
	if (!GC.getYieldInfo(eYield).isCargo())
	{
		return false;
	}
	
	bool bFinal = true;
	
	switch (eYield)
	{
		case YIELD_FOOD:
		case YIELD_LUMBER:
		case YIELD_STONE:										//	KJ RESOURCES
			bFinal = false;
			break;
			
		case YIELD_ORE:			
		case YIELD_SILVER:
		case YIELD_GOLD:										//MORE_YIELD_TYPES		05/05/09		Aymerick
		case YIELD_GEMS:										//	KJ RESOURCES		
			bFinal = true;
			break;

		case YIELD_COTTON:
		case YIELD_FUR:
		case YIELD_SUGAR:
		case YIELD_TOBACCO:
		case YIELD_DRUGS:										//	KJ RESOURCES
		case YIELD_INDIGO:										//MORE_YIELD_TYPES		05/05/09		Aymerick
		case YIELD_INCENSE:										//	KJ RESOURCES
		case YIELD_COFFEE:										//MORE_YIELD_TYPES		05/05/09		Aymerick
		case YIELD_COCOA:										//	KJ RESOURCES
		case YIELD_TEA:											//	KJ RESOURCES
		case YIELD_SPICES:										//	KJ RESOURCES
		case YIELD_IVORY:										//	KJ RESOURCES		
		case YIELD_EBONY:										//	KJ RESOURCES
		{
				int iLoop;
				CvCity* pLoopCity = NULL;
				for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
				{
					if (pLoopCity->AI_getNeededYield(eYield) > 0)
					{
						bFinal = false;
						break;
					}					
				}
			}
			break;
			
		case YIELD_CLOTH:
		case YIELD_COATS:
		case YIELD_RUM:
		case YIELD_CIGARS:
			bFinal = true;
			break;
			
		case YIELD_TOOLS:
		case YIELD_MUSKETS:
		case YIELD_HORSES:
			bFinal = false;
			break;
			
		case YIELD_TRADE_GOODS:
		case YIELD_ARTISANS_PRODUCTS:							//	KJ RESOURCES
		case YIELD_SLAVES:										//	KJ RESOURCES		
			bFinal = true;
			break;
			
		case YIELD_HAMMERS:
		case YIELD_BELLS:
		case YIELD_CROSSES:
			bFinal = false;
			FAssertMsg(false, "Selling intangibles?");
			break;
		default:
			FAssert(false);
	}
	
	return bFinal;	
}
However, same of resources were later used in the production lines and the correct distribution between bFinal = true and bFinal = false must be such:
Spoiler :
Code:
bool CvPlayerAI::AI_isYieldFinalProduct(YieldTypes eYield) const
{
	if (!GC.getYieldInfo(eYield).isCargo())
	{
		return false;
	}
	
	bool bFinal = true;
	
	switch (eYield)
	{
		case YIELD_FOOD:
		case YIELD_LUMBER:
			bFinal = false;
			break;
			
		case YIELD_STONE:										//	KJ RESOURCES
			bFinal = true;
			break;
			
		case YIELD_ORE:	
		{
				int iLoop;
				CvCity* pLoopCity = NULL;
				for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
				{
					if (pLoopCity->AI_getNeededYield(eYield) > 0)
					{
						bFinal = false;
						break;
					}					
				}
			}
			break;
			
		case YIELD_SILVER:
		case YIELD_GOLD:										//MORE_YIELD_TYPES		05/05/09		Aymerick
		case YIELD_GEMS:										//	KJ RESOURCES		
			bFinal = true;
			break;

		case YIELD_COTTON:
		case YIELD_FUR:
		case YIELD_SUGAR:
		case YIELD_TOBACCO:
		{
				int iLoop;
				CvCity* pLoopCity = NULL;
				for (pLoopCity = firstCity(&iLoop); pLoopCity != NULL; pLoopCity = nextCity(&iLoop))
				{
					if (pLoopCity->AI_getNeededYield(eYield) > 0)
					{
						bFinal = false;
						break;
					}					
				}
			}
			break;
			
			
		case YIELD_DRUGS:										//	KJ RESOURCES
		case YIELD_INDIGO:										//MORE_YIELD_TYPES		05/05/09		Aymerick
		case YIELD_INCENSE:										//	KJ RESOURCES
		case YIELD_COFFEE:										//MORE_YIELD_TYPES		05/05/09		Aymerick
		case YIELD_COCOA:										//	KJ RESOURCES
		case YIELD_TEA:											//	KJ RESOURCES
		case YIELD_SPICES:										//	KJ RESOURCES
		case YIELD_IVORY:										//	KJ RESOURCES		
		case YIELD_EBONY:										//	KJ RESOURCES
			bFinal = true;
			break;
			
		case YIELD_CLOTH:
		case YIELD_COATS:
		case YIELD_RUM:
		case YIELD_CIGARS:
			bFinal = true;
			break;
			
		case YIELD_TOOLS:
		case YIELD_MUSKETS:
		case YIELD_HORSES:
			bFinal = false;
			break;
			
		case YIELD_TRADE_GOODS:
		case YIELD_ARTISANS_PRODUCTS:							//	KJ RESOURCES
		case YIELD_SLAVES:										//	KJ RESOURCES		
			bFinal = true;
			break;
			
		case YIELD_HAMMERS:
		case YIELD_BELLS:
		case YIELD_CROSSES:
			bFinal = false;
			FAssertMsg(false, "Selling intangibles?");
			break;
		default:
			FAssert(false);
	}
	
	return bFinal;	
}
I compiled a new (fixed) CvGameCoreDLL.dll and could play up to 301 turn where one of my opponents declared independence. During testing my units were in the same place and I don't play. Here for me much more important was not to win but to see how the mod is running.
 
Top Bottom