Help with error message

RogerBacon

King
Joined
Nov 16, 2003
Messages
649
This is a small addition to the CulturalInfluence mod. It crashes when I try to set the occupation timer but it works fine if that is removed.
The error is at objTradeCity.changeOccupationTimer(iRevoltTimeRoll)

RuntimeError: unidentifiable C++ exception
ERR: Python function onEvent failed, module CvEventInterface

Code:
if (iCultureAttackRoll > iCultureDefenceRoll):
					# We have subverted their city
					objTradeCity.plot().setOwner(objCity.getOwner())
					iRevoltTimeRoll = gc.getGame().getMapRand().get(3,"Revolt Time Roll")
					iRevoltTimeRoll += 4
					if (not (objCity == None or objTradeCity.isNone())):
						objTradeCity.changeOccupationTimer(iRevoltTimeRoll)
					else:
						CvUtil.pyPrint("objTradeCity is none")

Any ideas?

Roger Bacon
 
RogerBacon said:
This is a small addition to the CulturalInfluence mod. It crashes when I try to set the occupation timer but it works fine if that is removed.
The error is at objTradeCity.changeOccupationTimer(iRevoltTimeRoll)

RuntimeError: unidentifiable C++ exception
ERR: Python function onEvent failed, module CvEventInterface

Code:
if (iCultureAttackRoll > iCultureDefenceRoll):
					# We have subverted their city
					objTradeCity.plot().setOwner(objCity.getOwner())
					iRevoltTimeRoll = gc.getGame().getMapRand().get(3,"Revolt Time Roll")
					iRevoltTimeRoll += 4
					if (not (objCity == None or objTradeCity.isNone())):
						objTradeCity.changeOccupationTimer(iRevoltTimeRoll)
					else:
						CvUtil.pyPrint("objTradeCity is none")

Any ideas?

Roger Bacon

Not too sure, hopefully this can help:

changeOccupationTimer calls setOccupationTimer, which, if the occupation of the city has changed (aka, the city goes from not being occupied to being occupied), calls each of:

updateCommerce();
updateMaintenance();
updateTradeRoutes();
updateCultureLevel();

I'm going to assume there's a problem in one of those.

However, we have a big storm coming, so I can't look too much into it now, 'cuz I need to shut down the computers :P Good luck.
 
RogerBacon said:
This is a small addition to the CulturalInfluence mod. It crashes when I try to set the occupation timer but it works fine if that is removed.
The error is at objTradeCity.changeOccupationTimer(iRevoltTimeRoll)

RuntimeError: unidentifiable C++ exception
ERR: Python function onEvent failed, module CvEventInterface

Code:
if (iCultureAttackRoll > iCultureDefenceRoll):
					# We have subverted their city
					objTradeCity.plot().setOwner(objCity.getOwner())
					iRevoltTimeRoll = gc.getGame().getMapRand().get(3,"Revolt Time Roll")
					iRevoltTimeRoll += 4
					if (not (objCity == None or objTradeCity.isNone())):
						objTradeCity.changeOccupationTimer(iRevoltTimeRoll)
					else:
						CvUtil.pyPrint("objTradeCity is none")

Any ideas?

Roger Bacon

I dont know, but I always use setOccupationTimer, the following works fine for me:

Code:
		if iBuildingType == gc.getInfoTypeForString('BUILDING_PURGE_THE_UNFAITHFUL'):
			pPlayer = gc.getPlayer(player)
			CyInterface().addMessage(pCity.getOwner(),True,25,'The Inquisition strikes again!','AS2D_INQUISITION',1,'Art/Interface/Buttons/Actions/Pillage.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
			for i in range(pPlayer.getNumCities()):
				iRnd = CyGame().getSorenRandNum(2, "Bob")
				pCity2 = pPlayer.getCity(i)
				StateBelief = pPlayer.getStateReligion()
				if StateBelief == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
					iRnd = iRnd - 1
				for iTarget in range(gc.getNumReligionInfos()):
					if (StateBelief != iTarget and pCity2.isHasReligion(iTarget) and pCity2.isHolyCityByType(iTarget) == False):
						pCity2.setHasReligion(iTarget, False, True, True)
						iRnd = iRnd + 1
						for i in range(gc.getNumBuildingInfos()):
							if gc.getBuildingInfo(i).getPrereqReligion() == iTarget:
								pCity2.setHasRealBuilding(i, False)
				if iRnd > 0:
					pCity2.setOccupationTimer(iRnd)
 
I've used changeOccupationTimer before with no problems.

As a quick experiment I commented out objTradeCity.plot().setOwner(objCity.getOwner()) and it runs fine; the changeOccupationTimer works. So, it seems to be the interaction between the two. Is it possible that when the city changes owner it gets a new id and that is why the call to changeOccupationTimer crashes the game? I would have thought my if condition would have caught something like that but, if that is indeed what is happening, aparently not.

Roger Bacon
 
RogerBacon said:
I've used changeOccupationTimer before with no problems.

As a quick experiment I commented out objTradeCity.plot().setOwner(objCity.getOwner()) and it runs fine; the changeOccupationTimer works. So, it seems to be the interaction between the two. Is it possible that when the city changes owner it gets a new id and that is why the call to changeOccupationTimer crashes the game? I would have thought my if condition would have caught something like that but, if that is indeed what is happening, aparently not.

Roger Bacon

Yeah, I was digging through the setOccupationTimer 'cuz I thought that the isNone would correctly catch the problem, but I just went into the console and typed those two commands and get the same problem, but when I type after changing the plot owner...

pCity.isNone()

it returns False. So, I don't think that isNone() correctly catches that the object is no longer valid.

It seems that the CvCity object will be deleted when the city changes hands during CvPlayer::acquireCity(), which I believe is called in CvPlot::setOwner(). But, I don't think that the CyCity object that points to the CvCity object notices this, since the python object doesn't check whether it's CvCity pointer is valid, only if it's NULL.

I guess I would just make a new city pointer by using plot().getPlotCity(), and checking that for None before using that pointer to set the occupation timer.
 
Gerikes said:
I guess I would just make a new city pointer by using plot().getPlotCity(), and checking that for None before using that pointer to set the occupation timer.

Thanks, that did it. :)

Roger Bacon

Code:
if (iCultureAttackRoll > iCultureDefenceRoll):
					# We have subverted their city
					theCityPlot = objTradeCity.plot()
					objTradeCity.plot().setOwner(objCity.getOwner())
					iRevoltTimeRoll = gc.getGame().getMapRand().get(3,"Revolt Time Roll")
					iRevoltTimeRoll += 4
					if (not (objCity == None or objTradeCity.isNone())):
						theNewCityPointer = theCityPlot.getPlotCity()
						theNewCityPointer.changeOccupationTimer(iRevoltTimeRoll)
						
					else:
						CvUtil.pyPrint("objTradeCity is none")
 
Back
Top Bottom