diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-11-17 10:13:38 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-29 19:13:48 +0200 |
commit | cebbaf1664f3005b3b9e66b104b9d4044b1ca277 (patch) | |
tree | 76bc7a5de519fdae634041abb714efc2442bdad1 /src | |
parent | 227e0675122e6b3a2256f3982b9c0e65d1cfc242 (diff) | |
download | minetest-cebbaf1664f3005b3b9e66b104b9d4044b1ca277.tar.gz minetest-cebbaf1664f3005b3b9e66b104b9d4044b1ca277.tar.bz2 minetest-cebbaf1664f3005b3b9e66b104b9d4044b1ca277.zip |
Catch SerializationError in CCraftDefManager::getCraftResult()
Diffstat (limited to 'src')
-rw-r--r-- | src/craftdef.cpp | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/src/craftdef.cpp b/src/craftdef.cpp index 79761b857..e701a4279 100644 --- a/src/craftdef.cpp +++ b/src/craftdef.cpp @@ -114,8 +114,8 @@ public: IGameDef *gamedef) const { if(input_cpi.width > 3){ - errorstream<<"getCraftResult: IGNORING ERROR: " - <<"input_cpi.width > 3"<<std::endl; + errorstream<<"getCraftResult(): ERROR: " + <<"input_cpi.width > 3; Failing to craft."<<std::endl; return NULL; } InventoryItem *input_items[9]; @@ -134,33 +134,42 @@ public: { CraftDefinition *def = *i; - infostream<<"Checking "<<createInput(input_cpi).dump()<<std::endl + /*infostream<<"Checking "<<createInput(input_cpi).dump()<<std::endl <<" against "<<def->input.dump() - <<" (output=\""<<def->output<<"\")"<<std::endl; - - CraftPointerInput spec_cpi = createPointerInput(def->input, gamedef); - if(spec_cpi.width > 3){ - errorstream<<"getCraftResult: IGNORING ERROR: " - <<"spec_cpi.width > 3"<<std::endl; - continue; + <<" (output=\""<<def->output<<"\")"<<std::endl;*/ + + try { + CraftPointerInput spec_cpi = createPointerInput(def->input, gamedef); + if(spec_cpi.width > 3){ + errorstream<<"getCraftResult: ERROR: " + <<"spec_cpi.width > 3 in recipe " + <<def->dump()<<std::endl; + continue; + } + InventoryItem *spec_items[9]; + for(u32 y=0; y<3; y++) + for(u32 x=0; x<3; x++) + { + u32 i=y*3+x; + if(x >= spec_cpi.width || y >= spec_cpi.height()) + spec_items[i] = NULL; + else + spec_items[i] = spec_cpi.items[y*spec_cpi.width+x]; + } + + bool match = checkItemCombination(input_items, spec_items); + + if(match){ + std::istringstream iss(def->output, std::ios::binary); + return InventoryItem::deSerialize(iss, gamedef); + } } - InventoryItem *spec_items[9]; - for(u32 y=0; y<3; y++) - for(u32 x=0; x<3; x++) + catch(SerializationError &e) { - u32 i=y*3+x; - if(x >= spec_cpi.width || y >= spec_cpi.height()) - spec_items[i] = NULL; - else - spec_items[i] = spec_cpi.items[y*spec_cpi.width+x]; - infostream<<"spec_items["<<i<<"] = "<<spec_items[i]<<std::endl; - } - - bool match = checkItemCombination(input_items, spec_items); - - if(match){ - std::istringstream iss(def->output, std::ios::binary); - return InventoryItem::deSerialize(iss, gamedef); + errorstream<<"getCraftResult: ERROR: " + <<"Serialization error in recipe " + <<def->dump()<<std::endl; + // then go on with the next craft definition } } return NULL; |