mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
Catch normal runtime errors instead of exiting with SIGABRT
This commit is contained in:
parent
5baa10ba95
commit
d9af9cbc9d
1 changed files with 25 additions and 26 deletions
|
@ -36,6 +36,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
|
|
||||||
|
@ -98,8 +99,7 @@ static void writeImage(const std::string &output, const uint8_t *data, bool colo
|
||||||
}
|
}
|
||||||
|
|
||||||
writeStamp(output, t);
|
writeStamp(output, t);
|
||||||
}
|
} catch (const std::exception& ex) {
|
||||||
catch (const std::exception& ex) {
|
|
||||||
std::remove(tmpfile.c_str());
|
std::remove(tmpfile.c_str());
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
@ -147,8 +147,7 @@ static void doRegion(const std::string &input, const std::string &output, const
|
||||||
|
|
||||||
writeImage(output, reinterpret_cast<const uint8_t*>(image.get()), true, intime);
|
writeImage(output, reinterpret_cast<const uint8_t*>(image.get()), true, intime);
|
||||||
writeImage(output_light, lightmap.get(), false, intime);
|
writeImage(output_light, lightmap.get(), false, intime);
|
||||||
}
|
} catch (const std::exception& ex) {
|
||||||
catch (const std::exception& ex) {
|
|
||||||
std::fprintf(stderr, "Failed to generate %s: %s\n", output.c_str(), ex.what());
|
std::fprintf(stderr, "Failed to generate %s: %s\n", output.c_str(), ex.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,8 +245,7 @@ static bool makeMipmap(const std::string &dir, size_t level, size_t x, size_t z,
|
||||||
}
|
}
|
||||||
|
|
||||||
writeStamp(output, t);
|
writeStamp(output, t);
|
||||||
}
|
} catch (const std::exception& ex) {
|
||||||
catch (const std::exception& ex) {
|
|
||||||
std::remove(tmpfile.c_str());
|
std::remove(tmpfile.c_str());
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
@ -281,22 +279,8 @@ static void makeMipmaps(const std::string &dir, Info *info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
static void doLevel(const std::string &inputdir, const std::string &outputdir) {
|
||||||
|
const std::string regiondir = inputdir + "/region";
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
using namespace MinedMap;
|
|
||||||
|
|
||||||
|
|
||||||
if (argc < 3) {
|
|
||||||
std::fprintf(stderr, "Usage: %s <data directory> <output directory>\n", argv[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string inputdir(argv[1]);
|
|
||||||
std::string regiondir = inputdir + "/region";
|
|
||||||
|
|
||||||
std::string outputdir(argv[2]);
|
|
||||||
|
|
||||||
makeDir(outputdir + "/map");
|
makeDir(outputdir + "/map");
|
||||||
makeDir(outputdir + "/map/0");
|
makeDir(outputdir + "/map/0");
|
||||||
|
@ -304,10 +288,8 @@ int main(int argc, char *argv[]) {
|
||||||
makeDir(outputdir + "/light/0");
|
makeDir(outputdir + "/light/0");
|
||||||
|
|
||||||
DIR *dir = opendir(regiondir.c_str());
|
DIR *dir = opendir(regiondir.c_str());
|
||||||
if (!dir) {
|
if (!dir)
|
||||||
std::fprintf(stderr, "Unable to read input directory: %s\n", std::strerror(errno));
|
throw std::system_error(errno, std::generic_category(), "Unable to read input directory");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
Info info;
|
Info info;
|
||||||
|
|
||||||
|
@ -331,6 +313,23 @@ int main(int argc, char *argv[]) {
|
||||||
makeMipmaps(outputdir, &info);
|
makeMipmaps(outputdir, &info);
|
||||||
|
|
||||||
info.writeJSON((outputdir + "/info.json").c_str());
|
info.writeJSON((outputdir + "/info.json").c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
if (argc < 3) {
|
||||||
|
std::fprintf(stderr, "Usage: %s <data directory> <output directory>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
MinedMap::doLevel(argv[1], argv[2]);
|
||||||
|
} catch (const std::runtime_error& ex) {
|
||||||
|
std::fprintf(stderr, "Error: %s\n", ex.what());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue