Game Development Community

Light Map Crashing

by Mark Dynna · in Torque Game Engine Advanced · 06/24/2008 (8:08 am) · 0 replies

We're experiencing a game crashing during mission lighting, but I'm having trouble tracking down the cause. The crash happens here:
bool SceneLighting::InteriorProxy::getPersistInfo(PersistInfo::PersistChunk * info)
{
	if(!Parent::getPersistInfo(info))
		return(false);

	PersistInfo::InteriorChunk * chunk = dynamic_cast<PersistInfo::InteriorChunk*>(info);
	AssertFatal(chunk, "SceneLighting::InteriorProxy::getPersistInfo: invalid info chunk!");

	InteriorInstance * interior = getObject();
	if(!interior)
		return(false);

	LM_HANDLE instanceHandle = interior->getLMHandle();

	AssertFatal(!chunk->mDetailLightmapCount.size(), "SceneLighting::InteriorProxy::getPersistInfo: invalid array!");
	AssertFatal(!chunk->mDetailLightmapIndices.size(), "SceneLighting::InteriorProxy::getPersistInfo: invalid array!");
	AssertFatal(!chunk->mLightmaps.size(), "SceneLighting::InteriorProxy::getPersistInfo: invalid array!");

	U32 numDetails = interior->getNumDetailLevels();
	U32 i;
	for(i = 0; i < numDetails; i++)
	{
		Interior * detail = interior->getDetailLevel(i);
		LM_HANDLE interiorHandle = detail->getLMHandle();

		Vector<GFXTexHandle> & baseHandles = gInteriorLMManager.getHandles(interiorHandle, 0);
		Vector<GFXTexHandle> & instanceHandles = gInteriorLMManager.getHandles(interiorHandle, instanceHandle);
		Vector<GFXTexHandle> &sgNLMHandles = gInteriorLMManager.getNormalHandles(interiorHandle, instanceHandle);

		U32 litCount = 0;

		// walk all the instance lightmaps and grab diff lighting from them
		for(U32 j = 0; j < instanceHandles.size(); j++)
		{
			if(!instanceHandles[j])
				continue;

			litCount++;
			chunk->mDetailLightmapIndices.push_back(j);

			GBitmap * baseBitmap = baseHandles[j]->getBitmap();
			GBitmap * instanceBitmap = instanceHandles[j]->getBitmap();

			Point2I extent(baseBitmap->getWidth(), baseBitmap->getHeight());

			[b]GBitmap * diffLightmap = new GBitmap(extent.x, extent.y, false);[/b]
In the stack trace right after the above bold line runs it attempts to allocate the memory, and then we get some sort of memory allocation error and eventually a crash due to "access violation."

At first I thought this was a problem with a particular DIF model, so I threw in some debug messages to see which DIF it was crashing on. I found a model and commented it out of the mission file, but that just produced the crash on a different model. We have tested pretty much every DIF we have in an isolated mission file (with just the model in it), so it must have something to do with the bunch of them being together.

We have 298 Interiors in our mission right now, and some of them are quite large. Is there some sort of maximum lightmap size that we are running into? It's really starting to seem like we are just running out of memory generating the light map.

Any help/suggestions would be appreciated. We've been stuck on this one for a few days now.