[SDK/XML] Problem with new text tag in XML

salaminizer

Colorado Internacional
Joined
Aug 12, 2006
Messages
221
Location
Porto Alegre, Brasil
The game is crashing when initializing. A quick (before it crashes lol) "attach to process" with the Debug DLL shows me that the game crashes when loading PromotionInfos.xml so it must be it.

I've added 2 new fields to the promotions: ActivateChance and ActivatePromotion.

In the schema:
Code:
<ElementType name="iActivateChance" content="textOnly" dt:type="int"/>
<ElementType name="iActivatePromotion" content="textOnly"/>

In the XML:
Code:
<iActivateChance>100</iActivateChance>		<iActivatePromotion>PROMOTION_STATUS_WARPED</iActivatePromotion>

PROMOTION_STATUS_WARPED is the Type of another promotion

The read, write and declarations are all there in the CvInfos.h and CvInfos.cpp
I think the problem is getting the text from the XML.

First I added

Code:
pXML->GetChildXmlValByName(&m_iActivatePromotion, "iActivatePromotion");

in the first read function.

Then I saw that when it was text sometimes the &variable was replaced with szTextVal and tried the same. Still crashing.

Then I saw that PromotionPrereq was in the second read function (read2). So I moved my tag there too, resulting in:

Code:
pXML->GetChildXmlValByName(szTextVal, "iActivatePromotion");
m_iActivatePromotion =  GC.getInfoTypeForString(szTextVal);

But it is still crashing when initializing the game.

Any ideas? Thanks.
 
Did you also add the tags in the schema under
<ElementType name="PromotionInfo" content="eltOnly">
?
 
Did you also add the tags in the schema under
<ElementType name="PromotionInfo" content="eltOnly">
?

yes, with minOccurs because I don't want to add to every promotion.

Code:
<element type="iActivateChance" minOccurs="0"/>
<element type="iActivatePromotion" minOccurs="0"/>
 
Placing the promotion with the text field in readpass2 was correct. Anything which refers to another <Type> item in the same file needs to be placed in readpass 2 to load properly.

Naming convention is that the "i" at the start of the field indicates you should use integer values, so really you should have your fields called "iActivateChance" and "ActivatePromotion", but that is only a convention and doesn't actually matter at all.


Really your load function seems to be exactly the way that it should be. Remove everything from the XML and try loading, or revert to your previous DLL and load using this new XML. That will let you know for certain that the issue IS in the DLL. Most likely that is the case though, so this would just be an excercise for peace of mind.


What are your other functions like? You declared the variable in the CvInfos.h file, then in the CvInfos.cpp you set an initial value for it?

You could also try using:
pXML->FindInInfoClass(szTextVal)

But it should have the same result, as the other function just calls this same operation IIRC
 
The initalization is:

Code:
m_iActivateChance(0),
m_iActivatePromotion(NO_PROMOTION)

actually, ActivateChance was set to NULL, but I compiled again with 0 and it crashed again. it's weird, I have added one other tag before and it was working.

hmm removing from the XML still crashed. I've done other changes to the SDK as well, but they are in CvUnit.cpp and I also expected them, if wrong, to crash in-game or at least starting the game because they are in updateCombat and doTurn.

other changes in CvInfos regarding promotions:

Code:
int CvPromotionInfo::getDuration() const
{
	return m_iDuration;
}

int CvPromotionInfo::getActivateChance() const
{
	return m_iActivateChance;
}

int CvPromotionInfo::getActivatePromotion() const
{
	return m_iActivatePromotion;
}

and in the .h:

Code:
DllExport int getDuration() const;
	DllExport int getActivateChance() const;
	DllExport int getActivatePromotion() const;

with Debug, stopped again at Civ4PromotionInfos.

Code:
LoadCivXml (xml\Units/CIV4PromotionInfos.xml)
HEAP[Civ4BeyondSword.exe]: Heap missing last entry in committed range near 1a62e558

:p I will compare the schema with BTS schema just to be sure everything's OK, or in the promotion file itself, there must be something wrong lol bah, schema is ok, promotion files is OK.

I haven't tried your FindInInfoClass, will try now too. -> same problem
 
If you have a debug running, set a breakpoint on the line which loads your Text field into szTextVal and step through the functions one-by-one, maybe it'll show you where the issue is, at the least it'll let you know if it is getting that far.
 
it doesn't even go that far, it's an AccessViolation problem.

Ok, today I added 3 new tags. I removed all the code related to them right now and it's working.

All my initalization, reading, etc. code is the SAME I used with other tag I have added the other day, so I'm at a loss here.

I'll take a slower look later, but I'll give you an example of the code that is already there:

get, which I made one for each new tag
Code:
int CvPromotionInfo::getExpireChance() const
{
	return m_iExpireChance;
}

Read:
Code:
stream->Read(&m_iExpireChance);

Write:
Code:
stream->Write(m_iExpireChance);

XML:
Code:
pXML->GetChildXmlValByName(&m_iExpireChance, "iExpireChance");

And default constructor:
Code:
m_iExpireChance(0)

All the lines related to the expire chance that actually do something are also working.

:confused:
 
ok, I'm attaching CvInfos.cpp and CvInfos.h for you to take a look and probably spot errors that I couldn't notice :p

please look for the lines with "me4x edit" comments.
in the default constructor of the promotion in the CPP the lines are a bit weird but they are commented, when I used them of course they were correct :p

thanks.
 

Attachments

  • cvinfos.rar
    87.8 KB · Views: 46
FIrst problem I see is in your initialization:
Code:
m_iExpireChance(0)
//m_iActivateChance(0),  //m_iDuration(-1)
//m_iActivatePromotion(NO_PROMOTION)//me4x edit 24/12/2008 rafael

Now, you may have removed the comma when you commented your lines out, but there needs to be a comma between each initialization, so the best way to handle it if you are adding new stuff to the end of the list is usually something like:

Code:
m_iExpireChance(0)
,m_iActivateChance(0),
m_iActivatePromotion(NO_PROMOTION)

Notice placing the comma at the start of your first line to handle the need for a new comma on the line above yours.


Really other than that everything looks fairly solid.
 
what is DllExport purpose ?

I don't know yet what's happening, but if I use one new tag, it works. I removed the other tag I added last time and it worked. if I have 2 or more new tags it crashes. I have but DllExport in both get methods, so that's why I'm asking.

:sad:

and yeah, the comma is alright when I uncomment it :p
 
DllExport lets the exe use that function. Since you cannot modify the EXE, you never need to use this for your new functions (and you should avoid removing it from any fields Firaxis placed it on, or changing the input types of such fields)
 
man, this sucks and does not make any SENSE AT ALL, but it says the memory cannot be "written"

I removed the DllExport, but still, the behaviour is the same: 1 tag works; more than 1, no deal.

--

gave up working with this version of the code. I have tried starting from scratch once again (copying from BTS folder) and now it.. worked. now I still have some other stuff to add again, I'll do it step by step.

well, thanks for trying to help me anyway :p
 
Top Bottom