View Full Version : Access violation error


Opera
Jan 23, 2010, 11:34 AM
I was skimming through the pedia after some modding and I got a RuntimeError: unidentified C++ exception in CvPediaMain; in placeCorporations, line: 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?

Afforess
Jan 23, 2010, 11:39 AM
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.

Opera
Jan 23, 2010, 12:03 PM
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...?

Opera
Jan 23, 2010, 12:30 PM
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?

The_J
Jan 23, 2010, 03:47 PM
Your HDD and RAM are okay?

Did you maybe add all the things to a part of the code, which is already memory intensive?

xienwolf
Jan 23, 2010, 05:25 PM
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).

Opera
Jan 23, 2010, 07:05 PM
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.

Opera
Jan 23, 2010, 07:24 PM
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

xienwolf
Jan 23, 2010, 09:48 PM
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.

Opera
Jan 24, 2010, 02:45 AM
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 :)

xienwolf
Jan 24, 2010, 11:29 AM
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.