I dusted off my Cata GitHub fork to do some debugging (Code:Blocks).
git fetch upstream
git checkout master
git reset --hard upstream/master
git push origin master --force
I haven’t added or modified any code, but I’m still getting an error on character creation in Curses version of the latest experimental (4b8532623f):
Can anyone deduce from the screenshot which .json file is having problems?
Troubleshooting I’ve done:
[ul][li]Tried both Release/Debug profiles[/li]
[li]Re-created world[/li]
[li]Tried multiple ways to generate character (Random, Preset, etc.)[/li][/ul]
Does the game produce a debug message? A lot of the JSON error stuff is listed in those messages in-game.
I re-tried running the game in Release to see if I could replicate the problem, but no in-game DEBUG message appears and my character seems to load without incident. The error only happens when I debug. I’m using this debugger:
GNU gdb (GDB) 7.4
I haven’t changed anything from the default in Code::Blocks…I also have VS 2010, but I noticed it threw about 8 errors when I loaded up the solution from the msvc100 folder and tried to build.
In the bottom left of the window it says buffer: CSC_WEAPON_PIERCING, that’s part of the recipes.json file. Also the stacktrace has load_recipe in it, so it actually fails to load a recipe.
Hmm, that’s odd. I did a Compare in Notepad++ of my recipes.json and the one from the repo and the files match. Does that mean there’s a bug with recipes.json, or is this a phantom debugger problem?
You can compare your code to the upstream version:
Also that error should lead to a debug message, what does it say?
The git diff command returned with nothing, so recipes.json must be identical to upstream. As for the debug message, all I see in the actual executable is the “Please wait while the world data loads” overlay on the home screen. Trying to Continue in Code::Blocks just keeps throwing the error.
I saved my previous custom .cbp file that I used to use, but it’s radically different. One thing I’m noticing is that there’s no mention of “makefile” anywhere in the current CataclysmWin.cbp…is that part of the problem?
Previous .cbp file
EDIT: I re-made the project from a .zip directly from the repo, just to be sure it wasn’t some problem with my fork. Same error.
I checked the load_recipe() function in the call stack. The recipe it’s getting stuck on is for javelin, every time. I looked at the json, but the formatting looks okay. Can anyone spot something there that I don’t see? It’s around line 1156.
I foolishly forgot to expand the “message” local variable in my screenshot: It reads:
Perhaps related to the new [["cook… thing? Try removing that line.
[quote=“Soyweiser, post:9, topic:5568”]Perhaps related to the new [["cook… thing? Try removing that line.[/quote]The error is definitely pointing at the array-of-arrays skill list, or rather the trying to load it (line 90 in crafting.cpp), but - that section is clearly put into a try-catch clause and it really shouldn’t cause anything - unless your debugger is set to throw errors on any and all exceptions.
if (!jsarr.empty()) {
// could be a single requirement, or multiple
try {
// try to parse as single requirement
requires_skills[jsarr.get_string(0)] = jsarr.get_int(1); <--line 90
} catch (std::string e) {
// get_string or get_int failed, so assume array of arrays
while (jsarr.has_more()) {
JsonArray ja = jsarr.next_array();
requires_skills[ja.get_string(0)] = ja.get_int(1);
}
}
}
Sean, that makes complete sense. How can I make the GDB only report uncaught exceptions?
[quote=“Mattaclysm, post:11, topic:5568”]Sean, that makes complete sense. How can I make the GDB only report uncaught exceptions?[/quote]I can’t find how to do that (heck, I can’t find how to configure the darn thing at all), but having tried out the debug function, it seems you can just power through using Continue, because there’s only a few items that throw these exceptions.
You’re right, again, Sean. The game continues after about 9 items. I really dislike the try/catch code for the JSON parsing, but I don’t know enough about JSON or C++ to propose a better option. Thanks for all the suggestions, everyone. You’ve helped me get debugging up and running!
Perhaps something like istream::peek exists for JSON parsing to check if there’s more than one skill required without triggering an exception?
EDIT: I took another look through the code, and it looks like we already have JsonIn::peek(). I’m hoping a better solution can be found to remedy the try/catch problem in crafting.cpp.
[quote=“Mattaclysm, post:13, topic:5568”]You’re right, again, Sean. The game continues after about 9 items. I really dislike the try/catch code for the JSON parsing, but I don’t know enough about JSON or C++ to propose a better option. Thanks for all the suggestions, everyone. You’ve helped me get debugging up and running!
Perhaps something like istream::peek exists for JSON parsing to check if there’s more than one skill required without triggering an exception?
EDIT: I took another look through the code, and it looks like we already have JsonIn::peek(). I’m hoping a better solution can be found to remedy the try/catch problem in crafting.cpp.[/quote]There’s a “has_array()” you can check for, substituting the try-catch for
if (!jsarr.empty()) {
// could be a single requirement, or multiple
if(!jsarr.has_array(0)){ // test if not array
requires_skills[jsarr.get_string(0)] = jsarr.get_int(1);
} else {
//it's not NOT an array, so jsarr is an array of arrays
while (jsarr.has_more()) {
JsonArray ja = jsarr.next_array();
requires_skills[ja.get_string(0)] = ja.get_int(1);
}
}
}
That works beautifully! No more hitting “Continue” through a bunch of exceptions
I see you’ve got an account on GitHub. Want to make a quick PR for this fix? I tested a few recipes in game using your code and everything seems to work normally.