Civic Attitude Modifier

Code:
 m_pszCivicAttitudeReason[i] = 0

That would be a failed initialization. Surprised it allowed you to attempt it. You want to use cDefault as the base value for that I think. Not sure as I have never had to personally initialize a string, you may be able to just use "" as easily.

Adding the pXML to your CNDr2 is trivial, I would suggest that may be the easier course (You just have to change CNDr2() to CNDr2(this) in CvXMLLoad, and then add the parameter to the header file for each CNDr2 function in CvInfos.h and .cpp. No requirement that you actually USE the field anywhere except right here where it is desired currently)
 
Code:
 m_pszCivicAttitudeReason[i] = 0
That would be a failed initialization. Surprised it allowed you to attempt it. You want to use cDefault as the base value for that I think. Not sure as I have never had to personally initialize a string, you may be able to just use "" as easily.

Changing it to cDefault changed nothing. It still crashed.

Adding the pXML to your CNDr2 is trivial, I would suggest that may be the easier course (You just have to change CNDr2() to CNDr2(this) in CvXMLLoad, and then add the parameter to the header file for each CNDr2 function in CvInfos.h and .cpp. No requirement that you actually USE the field anywhere except right here where it is desired currently)

Looks like how I am going to have to proceed. I'll see how that goes and report back.
 
Incredibly, I seem to have added the new parameter to all 118 or so functions in CvInfos, a few in CvInfoWater, and updated the code in CvXMLLoadUtilitySet perfectly. It loads fine. However, if I add the CND and CNDr2 code for CivicAttitudeModifiers, YOUR code mind, it still gives me a CTD. I copy-n-pasted your code directly, no changes...
 
Then all I can suggest is to set some breakpoints to figure out where/when the crash is happening. One at the start of your added code in ::readPass2, and another at the start of CNDr2. The previous crash was happening during the initialization of cDefault, because of a previous issue of writing outside the bounds of the array and corrupting the memory heap. Basically just watch for when your arrays are initialized and make sure that once done they aren't coming out the other side as garbage.
 
I did 2 major tests. First, I wanted to make sure I had added the new CvXMLLoadUtility* pXML parameter correctly, so I replaced the readpass2 code for PrereqProjects in CvProjectInfo with FF code. (Your code used InitList, while mine did not.) It worked just fine. This proves I added the new parameter correctly, crossing it off the list of things that could be a possible cause.

Now, I put a bunch of breakpoints on this code, and here is what I found.

Code:
if(!m_piCivicAttitudeChanges)
		pXML->InitList(&m_piCivicAttitudeChanges, GC.getNumCivicInfos(), 0);
	if(!m_pszCivicAttitudeReason)
		pXML->InitList(&m_pszCivicAttitudeReason, GC.getNumCivicInfos(), CvString(""));

This part executes fine. It does not crash.

However, when it reaches the first line of this code:

Code:
for (int i = 0; i < GC.getNumCivicInfos(); ++i)
	{
		if(pClassInfo->getCivicAttitudeChange(i) != 0)
			[COLOR="Red"]m_piCivicAttitudeChanges[i] = pClassInfo->getCivicAttitudeChange(i);[/COLOR]
		if(pClassInfo->getCivicAttitudeReason(i) != cDefault)
			m_pszCivicAttitudeReason[i] = pClassInfo->getCivicAttitudeReason(i);
	}

it crashes spectacularly. What does that mean?
 
What was the crash message, and what was the value of the attitude change array in pClassInfo before the crash? Does commenting out that line (and maybe the one after as well) stop the crash?

The error is

Unhandled exception at 0x75cab727 in Civ4BeyondSword.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0018cf94..

The pClassInfo's Civic Attitude Change is 0, and the m_piCivicAttitudeChanges was also 0...
 
The arrays ought to BE arrays, so having a single value is bothersome. But as EF said, the error is due to an overflow or mis-assignment, so either trying to make an array of negative or null size, or trying to store in a negative slot or beyond the last slot of an array.
 
That sounds like you're passing a negative or zero to "new foo[...]" or InitList().

The arrays ought to BE arrays, so having a single value is bothersome. But as EF said, the error is due to an overflow or mis-assignment, so either trying to make an array of negative or null size, or trying to store in a negative slot or beyond the last slot of an array.

How is this possible if my code looks exactly like yours at this point, Xienwolf? Does yours work okay?
 
Yes, mine works fine. It shouldn't be possible if your code is exactly the same as mine. The only thing I can think of is that I didn't have my code actually load a module which adjusts a civic. But I just now moved my test modifications into a module instead of the main XML, and even modified another civic (since I was testing with changes to civic 0, which may avoid some potential errors), my code still works.

Try removing your debugging code. You had initialized szMessage twice, though the second time was in a IF statement so SHOULD do a new instance of the variable, it isn't needed as the variable already exists and you are done with the previous value. But again, I had left that in my code without issue. Could be an OS deal, I am on XP SP3.
 
Yes, mine works fine. It shouldn't be possible if your code is exactly the same as mine. The only thing I can think of is that I didn't have my code actually load a module which adjusts a civic. But I just now moved my test modifications into a module instead of the main XML, and even modified another civic (since I was testing with changes to civic 0, which may avoid some potential errors), my code still works.

Try removing your debugging code. You had initialized szMessage twice, though the second time was in a IF statement so SHOULD do a new instance of the variable, it isn't needed as the variable already exists and you are done with the previous value. But again, I had left that in my code without issue. Could be an OS deal, I am on XP SP3.

IS there any way for you to test if it's an OS issue? At this point, I'm having to resort to hardcoding everything :sad:. The only other idea I had was that I wondered if this problem would go away if I moved this into a new XML file that I could create.... But I don't know enough to know if that would be a waste of time or actually work.
 
No way I could test if it is an OS issue, I only have the one computer which I run Civ and code on. Actually I don't think any of the computers I have access to at work have Vista even if I were to try slipping things on there for a test.

Mostly only the szMessage bits would be any potential OS related issue, so just clip all of that out since it was for debugging and isn't viable for the current debugging requirements anyway.
 
No way I could test if it is an OS issue, I only have the one computer which I run Civ and code on. Actually I don't think any of the computers I have access to at work have Vista even if I were to try slipping things on there for a test.

Mostly only the szMessage bits would be any potential OS related issue, so just clip all of that out since it was for debugging and isn't viable for the current debugging requirements anyway.

I still CTD when loading. Anyway, I'm not sure that was the cause, since I could load it up fine w/o WoC.
 
I'm so stupid.

Let's start over; with the basics. What is readpass2, really? A simplified version of ReadPass3. And if Readpass2 doesn't work; ReadPass3 Always Does.

I've familairized myself with ReadPass3's in the recent week, I added two new ones for Corporations. One of them should have been a ReadPass2, but WoC wrecked Corporation's ReadPass2 ability.

I'll attempt this using a ReadPass3, and report back.
 
Mostly, ease of choice when adding new elements where there wasn't already a pass 2, and construction of new pass 3s in a few places where they don't exist yet. I'd also move all pass 3s to the very bottom of the loading routine, where currently some are done before many files have loaded. But mostly you would dodge the modular loading issues of pass2 which exist in non-WoC code.
 
Top Bottom