Assert failed, have never seen this, help

NotSoGood

Emperor
Joined
Jan 25, 2009
Messages
1,077
Location
Finland
I managed to build my first debug dll and tried to fix an error that has been occuring in my mod. It crashed always when loading xml. Then i tried running the mod with debug dll and got a strange error message.

I haven't seen this kind of message before so if anyone could tell me what exactly it tells? I took closer look on that CvXMLLoadUtilitySet.cpp line 1337. Here's the whole function
Spoiler :
Code:
//------------------------------------------------------------------------------------------------------
//
//  FUNCTION:   SetGlobalClassInfo - This is a template function that is USED FOR ALMOST ALL INFO CLASSES.
//		Each info class should have a read(CvXMLLoadUtility*) function that is responsible for initializing
//		the class from xml data.
//
//  PURPOSE :   takes the szTagName parameter and loads the ppszString with the text values
//				under the tags.  This will be the hints displayed during game initialization and load
//
//------------------------------------------------------------------------------------------------------
template <class T>
void CvXMLLoadUtility::SetGlobalClassInfo(std::vector<T*>& aInfos, const char* szTagName, bool bTwoPass)
{
	char szLog[256];
	sprintf(szLog, "SetGlobalClassInfo (%s)", szTagName);
	PROFILE(szLog);
	logMsg(szLog);

	// if we successfully locate the tag name in the xml file
	if (gDLL->getXMLIFace()->LocateNode(m_pFXml, szTagName))
	{
		// loop through each tag
		do
		{
			SkipToNextVal();	// skip to the next non-comment node

				T* pClassInfo = new T;

				FAssert(NULL != pClassInfo);
				if (NULL == pClassInfo)
				{
					break;
				}

				bool bSuccess = pClassInfo->read(this);
				[COLOR="Red"]FAssert(bSuccess);[/COLOR]
				if (!bSuccess)
				{
					delete pClassInfo;
					break;
				}

			int iIndex = -1;
			if (NULL != pClassInfo->getType())
			{
				iIndex = GC.getInfoTypeForString(pClassInfo->getType(), true);
			}

			if (-1 == iIndex)
			{
				aInfos.push_back(pClassInfo);
				if (NULL != pClassInfo->getType())
				{
					GC.setInfoTypeFromString(pClassInfo->getType(), (int)aInfos.size() - 1);	// add type to global info type hash map
				}
			}
			else
			{
				SAFE_DELETE(aInfos[iIndex]);
				aInfos[iIndex] = pClassInfo;
			}


		} while (gDLL->getXMLIFace()->NextSibling(m_pFXml));

		if (bTwoPass)
		{
			// if we successfully locate the szTagName node
			if (gDLL->getXMLIFace()->LocateNode(m_pFXml, szTagName))
			{
				gDLL->getXMLIFace()->SetToParent(m_pFXml);
				gDLL->getXMLIFace()->SetToChild(m_pFXml);

				// loop through each tag
				for (std::vector<T*>::iterator it = aInfos.begin(); it != aInfos.end(); ++it)
				{
					SkipToNextVal();	// skip to the next non-comment node

					(*it)->readPass2(this);

					if (!gDLL->getXMLIFace()->NextSibling(m_pFXml))
					{
						break;
					}
				}
			}
		}
	}
}
The red line is the line 1337. I have actually no idea how to fix this. Could this be because of the new promotion tags I have added to DLL and xml?
 
Unfortunately most mods have dozens of these failing asserts. I just click "ignore always". It is possible, but unlikely, that these asserts are the direct cause of your crash. Often, you have copied some other peoples' code to start your own sdk mod. If so, first compile their code without any of your changes and run it. You will probably get the same asserts; this way you can be sure it is not "your fault".

IMHO, a better way to find this type of crash is to use civchecker. It is more likely that you have some missing art file or other undefined symbol in your xml. Civchecker will catch this.
 
Unfortunately most mods have dozens of these failing asserts. I just click "ignore always". It is possible, but unlikely, that these asserts are the direct cause of your crash. Often, you have copied some other peoples' code to start your own sdk mod. If so, first compile their code without any of your changes and run it. You will probably get the same asserts; this way you can be sure it is not "your fault".

IMHO, a better way to find this type of crash is to use civchecker. It is more likely that you have some missing art file or other undefined symbol in your xml. Civchecker will catch this.

That's actually code from original BTS 3.19, atleast think so 'cos I can't see anyone's comments there. That actually can't even be ignored because it causes the mod to crash. That's why I'm using debug dll to find the reason for crashes.
And I have used that tool, it's useful but I couldn't find anything that could have done it. I did managed to fix some craphics though. :D
 
How did you establish that this assert code is the direct cause of the crash?

Hmm, I think you found a weak spot in my theory. :lol:
Mostly I just presumed so because of three reasons:

1) The mod used to crash constantly after i added those two new promotion tags, now it has been working though. (Might be because of that not working makefile) It has also been confirmed that my dll with promotion doesn't work properly with other mods. (Also might be because of that not working makefile or something else)

2) When the mod crashed, the xml log always stopped
Code:
[4182.468] Loading XML file xml\Units/CIV4PromotionInfos.xml
[4182.515] Load XML file xml\Units/CIV4PromotionInfos.xml SUCCEEDED
[4182.531] SetGlobalClassInfo (Civ4PromotionInfos/PromotionInfos/PromotionInfo)
[4182.531] info type NONE not found, Current XML file is: xml\Units/CIV4PromotionInfos.xml
[4182.531] info type NONE not found, Current XML file is: xml\Units/CIV4PromotionInfos.xml
[4182.531] info type NONE not found, Current XML file is: xml\Units/CIV4PromotionInfos.xml
[4182.531] info type NONE not found, Current XML file is: xml\Units/CIV4PromotionInfos.xml
[4182.531] info type NONE not found, Current XML file is: xml\Units/CIV4PromotionInfos.xml
[4182.531] info type NONE not found, Current XML file is: xml\Units/CIV4PromotionInfos.xml

3) When I got the makefile working and managed to build a debug DLL. Used it, and saw that message, that somehow fits in your previous suspects. It's very suspicious. ;)

That's basicly why I thought it to be the cause of crash, but I didn't knew about the makefile then. Tomorrow I'll see if the new makefile fixed that error. My mod used to stop working the next day even if I didn't do anything. :D
It would be great if that assert failed message wasn't actually anything big.
 
That is a useless assert. ignore or delete it. Basically it is telling you that you have a comment in your XML which it tried to load as an entry. Right after the assert it cleans itself up, so nothing in the code actually goes bad. The Assert was placed by Firaxis most likely so they could quickly locate and remove comments in the XML, then was left in place with no explanation, making it useless for modders.
 
That is a useless assert. ignore or delete it. Basically it is telling you that you have a comment in your XML which it tried to load as an entry. Right after the assert it cleans itself up, so nothing in the code actually goes bad. The Assert was placed by Firaxis most likely so they could quickly locate and remove comments in the XML, then was left in place with no explanation, making it useless for modders.

That's good to know. I might actually delete it so I won't confuse it to something bad. Do I just delete this line in red
Code:
			SkipToNextVal();	// skip to the next non-comment node

				T* pClassInfo = new T;

				FAssert(NULL != pClassInfo);
				if (NULL == pClassInfo)
				{
					break;
				}

				bool bSuccess = pClassInfo->read(this);
				[COLOR="Red"]FAssert(bSuccess);[/COLOR]
				if (!bSuccess)
				{
					delete pClassInfo;
					break;
				}
or is there something else that's part of this "assert"?
 
info type NONE not found, Current XML file is: xml\Units/CIV4PromotionInfos.xml

BTW, is this telling you that you should have PROMOTION_NONE or something else instead of NONE in the XML? It is looking up a string using getInfoTypeForString() but not finding it. That's generally a bad thing. It probably returns -1 in that case which is the same thing usually, and using PROMOTION_NONE (or whatever NONE that is) may end up with that warning anyway.
 
BTW, is this telling you that you should have PROMOTION_NONE or something else instead of NONE in the XML? It is looking up a string using getInfoTypeForString() but not finding it. That's generally a bad thing. It probably returns -1 in that case which is the same thing usually, and using PROMOTION_NONE (or whatever NONE that is) may end up with that warning anyway.

I have always thought that they are because of those NONEs in the xml files.
Code:
		<PromotionInfo>
			<Type>PROMOTION_COMBAT1</Type>
			<Description>TXT_KEY_PROMOTION_COMBAT1</Description>
			<Sound>AS2D_IF_LEVELUP</Sound>
			<LayerAnimationPath>[COLOR="Red"]NONE[/COLOR]</LayerAnimationPath>
			<PromotionPrereq>[COLOR="red"]NONE[/COLOR]</PromotionPrereq>
			<PromotionPrereqOr1>[COLOR="red"]NONE[/COLOR]</PromotionPrereqOr1>
			<PromotionPrereqOr2>[COLOR="red"]NONE[/COLOR]</PromotionPrereqOr2>
			<TechPrereq>[COLOR="red"]NONE[/COLOR]</TechPrereq>
			<StateReligionPrereq>[COLOR="red"]NONE[/COLOR]</StateReligionPrereq>
Even the original BTS' xml log is full of those. I thought it's because the game searches that string NONE if it's defined somewhere but it can't find it. That's why it prints that in the xml log, but I never thought they could be bad. :confused:
 
No I think they are okay. They are not found by getInfoTypeForString() which returns -1. All of the NONEs (PLAYER_NONE, TECH_NONE, etc) are defined to be -1. So it works out. I didn't know those error messages were in the vanilla BTS. If so, they are clearly fine.
 
It would be trivial to place "NONE" into the data structure as -1 so it is returned as a normal value. This would remove all of those error messages from the logs with no change in logic/gameplay.
 
There must be a call to setInfoTypeForString(char*, int) or something. Just pass in "NONE" and -1. This will register that value in the data structure for all info type keys.
 
It's easier than that. Look in CvEnums.h. You'll find everything you need there.
 
Care to be a little more specific? Teasing isn't nice! :p

But it's so much funnnn...

Okay, here. In CvEnums.h, do a find and replace all. Put this in the find bar "-1," and this in the replace bar "-1,\n NONE = -1,". That will add a NONE to equal -1 every time a -1 is defined. Otherwise it's a bit tedious to add 128 of them yourself.
 
I don't see how that would affect calls to getInfoTypeForString().

Sigh...

CvEnums are were all the Strings are hardcoded to return specific values. If you look, it's where it says things like NO_PROMOTION = -1, and NO_IMPROVEMENT = -1. It doesn't affect the value of getInfoTypeForString at all, except it should get rid of the error messages in the logs, which was the original complaint, yes?
 
Top Bottom