Pointer error - how to debug?

Lemon Merchant

Not Quite Sonic
Retired Moderator
Joined
Jun 27, 2008
Messages
8,773
Location
Red Sector A
I had posted part of this in Asaf's "Compiling the DLL" thread but this is probably a better place.

I have merged the SDK files from Stolenray's Advanced Diplomacy, into Better BAT AI. It compiles fine, but I'm getting this popup when I'm trying to run in debug mode:

Capture18.PNG

I get a CTD when running the release DLL.

I'm told that this is a pointer error, and I have no idea how to debug it, since going back to debug mode (it offers to debug for me) takes me into disassembly. I don't do so bad with C++ or C#, but assembly code is beyond me. Am I doing something wrong here?

Also, can loading XML tags in the wrong order cause something like this?

Any guidance would be appreciated. (And thanks to Folket for pointing out that it's a pointer error.)
 
If you compiled a debug DLL and the debugger takes you to assembly, then it is most likely inside the exe and not the DLL. The most likely reason for this would be that the exe requests a pointer from the DLL and it returns a NULL pointer. The exe then uses the pointer without checking if it is a NULL pointer. Alternatively it gets a pointer to something where you have freed the memory.

I really hate this kind of bugs because the debugger is fairly useless in telling where the actual bug is. Usually you have to backtrace based on your last code change, but it looks like you didn't just write 30 lines of code yourself meaning looking at your recent coding is not really helpful either.

Sometimes you are lucky and you can go backwards in the stack to reach something in the DLL and you have an indication where it went wrong. If every single line in the stack is ASM, then you have a serious problem.

Maybe it would be an idea to test each modcomp individually to see if it is in fact the merge itself, which broke something.

Also, can loading XML tags in the wrong order cause something like this?
Most unlikely. XML loading order doesn't matter unless file A refers to a tag in file B. In that case file B has to be read first.

I grew so tired of XML load order issues that I rewrite the whole setup in Medieval Conquest. It now reads all XML tags and then it reads the files. That way order doesn't really matter anymore and you can even have file A referring to file B while B refers to A. Quite useful, but it doesn't help solving the crash.
 
Thanks for the info. It looks like it's going to be tough. I've managed to get the release DLL to load without a crash (XML errors), but the "Options" menu item on the main menus won't work. I wonder if these things are related? The rest of the game plays fine, but defaults to vanilla settings and you can't change the graphics, music, etc...
 
Make sure that you also copy the CvGameCoreDLL.pdb file into your assets directory. That sometimes helps the debugger provide you with more information.
 
Make sure that you also copy the CvGameCoreDLL.pdb file into your assets directory. That sometimes helps the debugger provide you with more information.
I never had that problem, but it should be fairly easy to test. Just add
Code:
FAssert(false);
in a place you know you will reach, such as CvXMLLoadUtility::LoadPlayerOptions(). Debug when the assert fails. You should enter the code itself if your debug DLL works as intended and you see ASM if the pdb file is missing.

You could also use a breakpoint, but the assert removes the risk that you pass the function before you attach the debugger to the game.
 
OK, the problem with the Options screen was the Civilization4.ini file. There was some garbage that got in there, once I deleted it, all was good.

As I said, I can run the normal release DLL, but not the debug one. I tried to debug the normal BULL DLL that I use in BAT and it won't debug either - same type of error. I'm thinking that I have some sort of issue with my VS2010 setup, or something in the debug settings is wrong. I tried copying over the PDB files, too, but it still dumps me to assembly code when I debug. The message is "No source available". I'm thinking the problem is not with my code...
 
Back
Top Bottom