Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"forcing MSVC stacktrace to show which T we're talking about." error #980

Closed
A-Starfinder opened this issue Feb 23, 2018 · 8 comments
Closed
Labels

Comments

@A-Starfinder
Copy link

Hello, I am a beginner at c++ and get this error message, when I try to run my code:

Error C2338 forcing MSVC stacktrace to show which T we're talking about. ConsoleRPG c:...\nlohmann\json.hpp 1207
Error C2065 "force_msvc_stacktrace": undeclared identifier ConsoleRPG c:...\nlohmann\json.hpp 1206
Error C2039 "force_msvc_stacktrace": is not a member of "Item" ConsoleRPG c:...\nlohmann\json.hpp 1206
Error C2338 could not find from_json() method in T's namespace ConsoleRPG c:...\nlohmann\json.hpp 1202

I already read this thread: #929

I could still not locate the error.

The only thing I assign to json values is like this:
nlohmann::json itemJ = json::parse("string")
or having them as parameters in functions.

@A-Starfinder
Copy link
Author

I am using Visual Studio 2017

@nlohmann
Copy link
Owner

How does the exact code look like? The above error message is not triggered by parsing, but by trying to assign some user-defined object to json.

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Feb 23, 2018
@gregmarr
Copy link
Contributor

@nlohmann The error was from_json, not to_json, so it is indeed caused by parsing.

@nlohmann
Copy link
Owner

nlohmann commented Feb 23, 2018

@gregmarr Right. Then it was an assignment from json to a user-defined object. But this is not an issue in the deserialization process (what I mean with "parsing").

@A-Starfinder
Copy link
Author

A-Starfinder commented Feb 23, 2018

Ok, here all parts of the code, where I use nlohmann::json , sorry if my code is bad, but I am still a beginner and not used to c++:

bool ItemLoader::loadItems()
{
	std::ifstream itemFile("SaveFiles/items.json");
	if (!itemFile.is_open()) return false;
	json itemJ = json::parse(itemFile);
	int i = 0;
	while (!itemJ["Items"][i].is_null())
	{
		addItem(itemJ, i);
		i++;
	}
	itemFile.close();
	return true;
}
void ItemLoader::addItem(json itemJ, int i)
{
	Item item;

	item.id = itemJ["Items"][i]["ID"];
	item.itemName = itemJ["Items"][i]["Name"];
	item.weight = itemJ["Items"][i]["weight"];
	item.itemClass = itemClassParser(itemJ["Items"][i]["ItemClass"]);
	item.itemRarity = itemRarityParser(itemJ["Items"][i]["ItemRarity"]);
	item.itemAbilities = createAbilityVector(itemJ, i);

	if (item.itemClass == ItemClass::chestplate || item.itemClass ==  ItemClass::gloves || item.itemClass == ItemClass::headgear || item.itemClass == ItemClass::legs) item.defense = itemJ["Items"][i]["defense"];
	else if (item.itemClass == ItemClass::weapon || item.itemClass == ItemClass::magicalWeapon) {
		item.physicalAttack = itemJ["Items"][i]["physicalAttack"];
		item.magicAttack = itemJ["Items"][i]["magicAttack"];
		item.weaponType = weaponTypeParser(itemJ["Items"][i]["weaponType"]);
		item.ranged = itemJ["Items"][i]["ranged"];
	}

	items.push_back(item);

	return;
}
std::vector<ItemAbility> ItemLoader::createAbilityVector(json itemJ, int i)
{
	std::vector<ItemAbility> abilities;
	int c = 0;
	while (!itemJ["Items"][i]["abilities"][c].is_null())
	{
		ItemAbility ability;

		ability.abilityType = itemAbilityTypeParser(itemJ["Items"][i]["abilities"][c]["AbilityType"]);

		if (ability.abilityType == ItemAbilityType::statIncrease) {

			ability.statToIncrease = itemJ["Items"][i]["abilities"][c]["statToIncrease"];
			ability.increasingAmount = itemJ["Items"][i]["abilities"][c]["increasingAmount"];

			abilities.push_back(ability);
		}
		else if (ability.abilityType != ItemAbilityType::none){
			ability.abilityFile = itemJ["Items"][i]["abilities"][c]["abilityFile"];
		}
		abilities.push_back(ability);
		c++;
	}
	return abilities;
}
character::character()
{
	characterFile = "SaveFiles/character.json";
	loadCharacter();
}
bool character::loadCharacter()
{
	std::ifstream charFile(characterFile);
	if (!charFile.is_open()) return false;
	json charJ = json::parse(charFile);

	//load Status
	status.agility = charJ["Status"]["agility"];
	status.attributePoints = charJ["Status"]["attributePoints"];
	status.charisma = charJ["Status"]["charisma"];
	status.intelligence = charJ["Status"]["intelligence"];
	status.luck = charJ["Status"]["luck"];
	status.perception = charJ["Status"]["perception"];
	status.skill = charJ["Status"]["skill"];
	status.spiritAffinity = charJ["Status"]["spiritAffinity"];
	status.spiritArmor = charJ["Status"]["spiritArmor"];
	status.spiritEnergy = charJ["Status"]["spiritEnergy"];
	status.strength = charJ["Status"]["strength"];
	status.vitality = charJ["Status"]["vitality"];
	status.wisdom = charJ["Status"]["wisdom"];

	level = charJ["level"];
	attackMultiplier = charJ["Attack Multiplier"];
	name = charJ["name"];

	int count = 0;

	while (!charJ["inventory"][count].is_null()) {
		addItem(charJ["inventory"][count]);
		count++;
	}

	equipItem(charJ["Equipment"]["headgear"]);
	equipItem(charJ["Equipment"]["chestplate"]);
	equipItem(charJ["Equipment"]["gloves"]);
	equipItem(charJ["Equipment"]["legs"]);
	equipItem(charJ["Equipment"]["weapon1"]);
	equipItem(charJ["Equipment"]["weapon2"], 2);

	charFile.close();
	return true;
}

@nlohmann
Copy link
Owner

Then I would need to understand how, for instance, the Item class looks like. As debugging steps, could you try to comment the assignments from json to other types - maybe the error disappears and you can find the failing line when you remove the comments one by one?

@A-Starfinder
Copy link
Author

Ok, solved it. The error was on my side. Thank you a lot for your help and explaining the error.

@nlohmann
Copy link
Owner

Thanks for checking back!

@nlohmann nlohmann added platform: visual studio related to MSVC and removed state: needs more info the author of the issue needs to provide more details labels Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants