SDK Problem

Here it is:
Code:
void CvGame::newGame(int iWorldSize, int iClimate, int iSeaLevel, int iGameSpeed, int iNumPlayers, int* paiCivilizations, int* paiLeaderHeads, int* paiTeams)
{
	HandicapTypes eHandicap;
	int iI;
	bool bHumanPlayer = false;

	setFinalInitialized(false);

	eHandicap = GC.getInitCore().getHandicap((PlayerTypes)0);

	setGameTurn(0);

	GC.getInitCore().setWorldSize((WorldSizeTypes)iWorldSize);
	GC.getInitCore().setClimate((ClimateTypes)iClimate);
	GC.getInitCore().setSeaLevel((SeaLevelTypes)iSeaLevel);
	GC.getInitCore().setGameSpeed((GameSpeedTypes)iGameSpeed);

	for (iI = 0; iI < iNumPlayers; iI++)
	{
		// A bit cruddy, may be initializing teams more than once
		GET_TEAM((TeamTypes)iI).init((TeamTypes)paiTeams[iI]);
	}


	for (iI = 0; iI < iNumPlayers; iI++)
	{
	    GET_PLAYER((PlayerTypes)iI).setDisableHuman(false);

		if (GET_PLAYER((PlayerTypes)iI).isHuman())
		{
			bHumanPlayer = true;
		}
		else
		{
			bHumanPlayer = false;
		}

        if (GET_PLAYER((PlayerTypes)iI).isAlive())
        {
            GET_PLAYER((PlayerTypes)iI).clearResearchQueue();
            GET_PLAYER((PlayerTypes)iI).killUnits();
            GET_PLAYER((PlayerTypes)iI).killCities();
            GET_PLAYER((PlayerTypes)iI).killAllDeals();
        }

		GC.getInitCore().setLeader((PlayerTypes)iI, (LeaderHeadTypes)paiLeaderHeads[iI]);
		GC.getInitCore().setCiv((PlayerTypes)iI, (CivilizationTypes)paiCivilizations[iI]);
		GC.getInitCore().setTeam((PlayerTypes)iI, (TeamTypes)paiTeams[iI]);
		GC.getInitCore().setFlagDecal((PlayerTypes)iI, (CvWString)GC.getCivilizationInfo((CivilizationTypes)paiCivilizations[iI]).getFlagTexture());
		GC.getInitCore().setColor((PlayerTypes)iI, (PlayerColorTypes)GC.getCivilizationInfo((CivilizationTypes)paiCivilizations[iI]).getDefaultPlayerColor());
		GC.getInitCore().setArtStyle((PlayerTypes)iI, (ArtStyleTypes)GC.getCivilizationInfo((CivilizationTypes)paiCivilizations[iI]).getArtStyleType());

		GET_PLAYER((PlayerTypes)iI).init((PlayerTypes)iI);

		if (bHumanPlayer)
		{
			GC.getInitCore().setSlotStatus((PlayerTypes)iI, SS_TAKEN);
		}
		else
		{
			GC.getInitCore().setSlotStatus((PlayerTypes)iI, SS_COMPUTER);
		}

		GET_PLAYER((PlayerTypes)iI).setTurnActive(false);
	}

    logMsg("regen map start");
	// Regenerate map function snipped into bits.
	
	GC.getMapINLINE().erasePlots(); logMsg("regen map 1"); // First we need to remove the plots we already have

	float fWidth, fHeight;
	gDLL->getEngineIFace()->GetLandscapeGameDimensions(fWidth, fHeight);
	logMsg("LandscapeGameDimensions: %f, %f", fWidth, fHeight);

	// logMsg("Init data: %d, %d, %d, %d, %d, %d", GC.getWorldInfo(GC.getInitCore().getWorldSize()).getGridWidth() * 4, GC.getWorldInfo(GC.getInitCore().getWorldSize()).getGridHeight() * 4, GC.getMapINLINE().getTopLatitude(), GC.getMapINLINE().getBottomLatitude(), GC.getMapINLINE().isWrapX(), GC.getMapINLINE().isWrapY());

	CvMapInitData initData(GC.getWorldInfo(GC.getInitCore().getWorldSize()).getGridWidth() * 4, GC.getWorldInfo(GC.getInitCore().getWorldSize()).getGridHeight() * 4, GC.getMapINLINE().getTopLatitude(), GC.getMapINLINE().getBottomLatitude(), GC.getMapINLINE().isWrapX(), GC.getMapINLINE().isWrapY());

	gDLL->getEngineIFace()->GetLandscapeGameDimensions(fWidth, fHeight);

	// The following value should have changed. Looking at newly generated maps it would seem that each is 180 * numPlots. This does not change with map resize.
	logMsg("LandscapeGameDimensions: %f, %f", fWidth, fHeight);

	GC.getMapINLINE().init(&initData); logMsg("regen map 2");
	
	CvMapGenerator::GetInstance().generateRandomMap();  logMsg("regen map 3");
	CvMapGenerator::GetInstance().addGameElements(); logMsg("regen map 4");
	gDLL->getEngineIFace()->RebuildAllPlots(); logMsg("regen map 5");

	setInitialItems();  logMsg("regen map 6");

	initScoreCalculation();  logMsg("regen map 7");
	setFinalInitialized(true);  logMsg("regen map 8");
	GC.getMapINLINE().setupGraphical(); logMsg("regen map 9");
	gDLL->getEngineIFace()->SetDirty(GlobeTexture_DIRTY_BIT, true); logMsg("regen map 10");
	gDLL->getEngineIFace()->SetDirty(MinimapTexture_DIRTY_BIT, true); logMsg("regen map 11");
	gDLL->getInterfaceIFace()->setCycleSelectionCounter(1); logMsg("regen map 12");

	gDLL->getEngineIFace()->AutoSave(true); logMsg("regen map 13");

	logMsg("regen map successful");

	init(eHandicap);
	logMsg("reinit game successful");
	GET_PLAYER((PlayerTypes)0).setTurnActive(true);
}
I've been struggling for this one with quite a while as well. It seems crashes inside the .exe, rather then the .dll, but I'm not quite sure what is causing the crash.

I have a feeling it may be due to the incorrect working of gDLL->getEngineIFace()->GetLandscapeGameDimensions(fWidth, fHeight); after the map size has changed, however, I see no way to fix this. CvMap::pointToPlot is often seen in the stack trace of the crash, with a few .exe calls after it. pointToPlot uses the values for fWidth, and fHeight, which is my reasoning behind that being the problem.

Any help would be much appriciated! Once this is done, I can't see any more real difficulties.
 
Back
Top Bottom