Fix tools, cleanup, remove reinterpret_cast undefined behaviour
parent
61850bfb9b
commit
e00f5b7d2c
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -17,7 +18,7 @@
|
||||||
#include <Eigen/Core>
|
#include <Eigen/Core>
|
||||||
#include <fmt/ostream.h>
|
#include <fmt/ostream.h>
|
||||||
|
|
||||||
#include "celutil/bytes.h"
|
#include <celutil/bytes.h>
|
||||||
#include "3dschunk.h"
|
#include "3dschunk.h"
|
||||||
#include "3dsmodel.h"
|
#include "3dsmodel.h"
|
||||||
#include "3dsread.h"
|
#include "3dsread.h"
|
||||||
|
@ -34,8 +35,9 @@ using ProcessChunkFunc = std::int32_t (*)(std::istream &, std::uint16_t, std::in
|
||||||
|
|
||||||
bool readInt(std::istream& in, std::int32_t& value)
|
bool readInt(std::istream& in, std::int32_t& value)
|
||||||
{
|
{
|
||||||
in.read(reinterpret_cast<char*>(&value), sizeof(std::int32_t));
|
char buffer[sizeof(value)];
|
||||||
if (!in.good()) { return false; }
|
if (!in.read(buffer, sizeof(buffer)).good()) { return false; }
|
||||||
|
std::memcpy(&value, buffer, sizeof(value));
|
||||||
LE_TO_CPU_INT32(value, value);
|
LE_TO_CPU_INT32(value, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -43,8 +45,9 @@ bool readInt(std::istream& in, std::int32_t& value)
|
||||||
|
|
||||||
bool readShort(std::istream& in, std::int16_t& value)
|
bool readShort(std::istream& in, std::int16_t& value)
|
||||||
{
|
{
|
||||||
in.read(reinterpret_cast<char*>(&value), sizeof(std::int16_t));
|
char buffer[sizeof(value)];
|
||||||
if (!in.good()) { return false; }
|
if (!in.read(buffer, sizeof(buffer)).good()) { return false; }
|
||||||
|
std::memcpy(&value, buffer, sizeof(value));
|
||||||
LE_TO_CPU_INT16(value, value);
|
LE_TO_CPU_INT16(value, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -52,8 +55,9 @@ bool readShort(std::istream& in, std::int16_t& value)
|
||||||
|
|
||||||
bool readUshort(std::istream& in, std::uint16_t& value)
|
bool readUshort(std::istream& in, std::uint16_t& value)
|
||||||
{
|
{
|
||||||
in.read(reinterpret_cast<char*>(&value), sizeof(std::uint16_t));
|
char buffer[sizeof(value)];
|
||||||
if (!in.good()) { return false; }
|
if (!in.read(buffer, sizeof(buffer)).good()) { return false; }
|
||||||
|
std::memcpy(&value, buffer, sizeof(value));
|
||||||
LE_TO_CPU_INT16(value, value);
|
LE_TO_CPU_INT16(value, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -61,8 +65,9 @@ bool readUshort(std::istream& in, std::uint16_t& value)
|
||||||
|
|
||||||
bool readFloat(std::istream& in, float& value)
|
bool readFloat(std::istream& in, float& value)
|
||||||
{
|
{
|
||||||
in.read(reinterpret_cast<char*>(&value), sizeof(float));
|
char buffer[sizeof(value)];
|
||||||
if (!in.good()) { return false; }
|
if (!in.read(buffer, sizeof(buffer)).good()) { return false; }
|
||||||
|
std::memcpy(&value, buffer, sizeof(value));
|
||||||
LE_TO_CPU_FLOAT(value, value);
|
LE_TO_CPU_FLOAT(value, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
using namespace cmod;
|
using namespace cmod;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -41,7 +42,7 @@ int main(int argc, char* argv[])
|
||||||
string inputFileName = argv[1];
|
string inputFileName = argv[1];
|
||||||
|
|
||||||
cerr << "Reading...\n";
|
cerr << "Reading...\n";
|
||||||
M3DScene* scene = Read3DSFile(inputFileName);
|
std::unique_ptr<M3DScene> scene = Read3DSFile(inputFileName);
|
||||||
if (scene == nullptr)
|
if (scene == nullptr)
|
||||||
{
|
{
|
||||||
cerr << "Error reading 3DS file '" << inputFileName << "'\n";
|
cerr << "Error reading 3DS file '" << inputFileName << "'\n";
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
// as published by the Free Software Foundation; either version 2
|
// as published by the Free Software Foundation; either version 2
|
||||||
// of the License, or (at your option) any later version.
|
// of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <memory>
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "materialwidget.h"
|
#include "materialwidget.h"
|
||||||
#include "convert3ds.h"
|
#include "convert3ds.h"
|
||||||
|
@ -382,7 +384,7 @@ MainWindow::openModel(const QString& fileName)
|
||||||
|
|
||||||
if (info.suffix().toLower() == "3ds")
|
if (info.suffix().toLower() == "3ds")
|
||||||
{
|
{
|
||||||
M3DScene* scene = Read3DSFile(fileNameStd);
|
std::unique_ptr<M3DScene> scene = Read3DSFile(fileNameStd);
|
||||||
if (scene == nullptr)
|
if (scene == nullptr)
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, "Load error", tr("Error reading 3DS file %1").arg(fileName));
|
QMessageBox::warning(this, "Load error", tr("Error reading 3DS file %1").arg(fileName));
|
||||||
|
@ -396,8 +398,6 @@ MainWindow::openModel(const QString& fileName)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete scene;
|
|
||||||
|
|
||||||
// Generate normals for the model
|
// Generate normals for the model
|
||||||
double smoothAngle = 45.0; // degrees
|
double smoothAngle = 45.0; // degrees
|
||||||
double weldTolerance = 1.0e-6;
|
double weldTolerance = 1.0e-6;
|
||||||
|
|
Loading…
Reference in New Issue