Access violation error

Opera

Deity
Joined
Sep 21, 2008
Messages
4,643
I was skimming through the pedia after some modding and I got a RuntimeError: unidentified C++ exception in CvPediaMain; in placeCorporations, line:
Code:
			screen.setTableText(tableName, iColumn, iRow, u"<font=3>" + item[0] + u"</font>", gc.getCorporationInfo(item[1]).getButton(), WidgetTypes.WIDGET_PEDIA_JUMP_TO_CORPORATION, item[1], 1, CvUtil.FONT_LEFT_JUSTIFY)
Using a debug dll, I got that:
First-chance exception at 0x00682787 in Civ4BeyondSword.exe: 0xC0000005: Access violation reading location 0xd56a822a.
First-chance exception at 0x7c350440 in Civ4BeyondSword.exe: 0xC0000005: Access violation reading location 0x00000019.
First-chance exception at 0x7c350440 in Civ4BeyondSword.exe: 0xC0000005: Access violation reading location 0x00000019.
First-chance exception at 0x7c350440 in Civ4BeyondSword.exe: 0xC0000005: Access violation reading location 0x00000019.
First-chance exception at 0x00682787 in Civ4BeyondSword.exe: 0xC0000005: Access violation reading location 0xd56a822a.
Then I figured it was because of a check involving CvCorporation::getCrime(), so I commented out the check... And then the error was back at the below check. Using breakpoints, I managed to find that it breaks right when the function returns, in this case, m_iDefenseModifier.

What could that error be?
 
That error means you tried to use a getSomething(int i) call and it was out of bounds. So you tried to look up what corporation was at -1, or something like that. I can't tell until I see the code, but run a debug build, it will give you an assert right before usually.
 
I did run one, no assert, which surprised me... It really comes from WIDGET_PEDIA_JUMP_TO_CORPORATION, which calls ParseCorporationHelp (or something) which then calls to CvGameTextMgr::setCorporationHelp which then calls to CvCorporation::getCrime() which bugs.

As a note, I have added a new class in CvInfos, as well as a new pedia page, hence a new widget... Everything is working; at least everything I have added, since the corp page doesn't work anymore...

Edit: Oh, and every WIDGET_CLOSE_SCREEN are broken too... I'm willing to bet both bugs share some origin :p

Edit 2: With some more tests, it appears the defense modifier works like a charm, since it gets added to my city if I put the corporation in it... while the game can't use the exact same function to build the help string...?
 
Ok, so, now it shows up to 4 corporations and CtD's when I click on one of them :confused:

Edit: and now it doesn't show any corp anymore... wtf?
 
I did run one, no assert, which surprised me... It really comes from WIDGET_PEDIA_JUMP_TO_CORPORATION, which calls ParseCorporationHelp (or something) which then calls to CvGameTextMgr::setCorporationHelp which then calls to CvCorporation::getCrime() which bugs.

As a note, I have added a new class in CvInfos, as well as a new pedia page, hence a new widget... Everything is working; at least everything I have added, since the corp page doesn't work anymore...

Edit: Oh, and every WIDGET_CLOSE_SCREEN are broken too... I'm willing to bet both bugs share some origin :p

Edit 2: With some more tests, it appears the defense modifier works like a charm, since it gets added to my city if I put the corporation in it... while the game can't use the exact same function to build the help string...?

Typical error when you didn't add the widget to the end of the list. If you added it in the middle or start, then you bumped things down and now something isn't aligned properly. Either a hardcode in the exe (as I suspect is the case with close screen, comes up a lot) or a failure to do a full rebuild after changing CvEnums.h (which always makes things weird).
 
Typical error when you didn't add the widget to the end of the list. If you added it in the middle or start, then you bumped things down and now something isn't aligned properly. Either a hardcode in the exe (as I suspect is the case with close screen, comes up a lot) or a failure to do a full rebuild after changing CvEnums.h (which always makes things weird).
So you think the error is in CvEnums.h? But you didn't add CIVILOPEDIA_PAGE_TRAIT to the end, iirc. But you did add WIDGET_PEDIA_JUMP_TO_TRAIT to the end... Ah, I'll test that then.
 
Bug fixed! Thank you so much xienwolf :D
At least, when I'd want to add new widgets, I'll know I'd have to put them at the end :p
 
It is best to get in the habit of always working at the end of everything so that you can avoid such issues as this one. Just not a habit I forced on myself in my earlier days of coding. But I do intend to be more diligent in my rebuild. It really isn't an issue till you run into something which is hardcoded in the EXE or another DLL.
 
For some reason, I thought I had to put my new widget in the same order as the pedia. I guess there's really few cases in which order do matter :)
 
Order is only really important for the hardcode/xml hybrid systems, like GameOptions. Things that are listed completely in the SDK, but also exist in the XML. Since the XML is loaded in order, that is how it tries to match up.
 
Top Bottom