Fixed memsetting non-trivially-copyable types

Types stl_stats, stl_normal and SurfaceFillParams should not be zeroed by memset
This is not correct and also triggered warnings on gcc
This commit is contained in:
Lukas Matena 2019-09-24 17:09:07 +02:00
parent 7861fa5086
commit b67d8c1614
4 changed files with 43 additions and 43 deletions

View File

@ -89,33 +89,34 @@ struct stl_neighbors {
};
struct stl_stats {
stl_stats() { this->reset(); }
void reset() { memset(this, 0, sizeof(stl_stats)); this->volume = -1.0; }
char header[81];
stl_type type;
uint32_t number_of_facets;
stl_vertex max;
stl_vertex min;
stl_vertex size;
float bounding_diameter;
float shortest_edge;
float volume;
int connected_edges;
int connected_facets_1_edge;
int connected_facets_2_edge;
int connected_facets_3_edge;
int facets_w_1_bad_edge;
int facets_w_2_bad_edge;
int facets_w_3_bad_edge;
int original_num_facets;
int edges_fixed;
int degenerate_facets;
int facets_removed;
int facets_added;
int facets_reversed;
int backwards_edges;
int normals_fixed;
int number_of_parts;
stl_stats() { memset(&header, 0, 81); }
char header[81] = "";
stl_type type = (stl_type)0;
uint32_t number_of_facets = 0;
stl_vertex max = stl_vertex::Zero();
stl_vertex min = stl_vertex::Zero();
stl_vertex size = stl_vertex::Zero();
float bounding_diameter = 0.f;
float shortest_edge = 0.f;
float volume = -1.f;
int connected_edges = 0;
int connected_facets_1_edge = 0;
int connected_facets_2_edge = 0;
int connected_facets_3_edge = 0;
int facets_w_1_bad_edge = 0;
int facets_w_2_bad_edge = 0;
int facets_w_3_bad_edge = 0;
int original_num_facets = 0;
int edges_fixed = 0;
int degenerate_facets = 0;
int facets_removed = 0;
int facets_added = 0;
int facets_reversed = 0;
int backwards_edges = 0;
int normals_fixed = 0;
int number_of_parts = 0;
void clear() { *this = stl_stats(); }
};
struct stl_file {
@ -124,7 +125,7 @@ struct stl_file {
void clear() {
this->facet_start.clear();
this->neighbors_start.clear();
this->stats.reset();
this->stats.clear();
}
size_t memsize() const {

View File

@ -15,40 +15,39 @@ namespace Slic3r {
struct SurfaceFillParams
{
SurfaceFillParams() : flow(0.f, 0.f, 0.f, false) { memset(this, 0, sizeof(*this)); }
// Zero based extruder ID.
unsigned int extruder;
unsigned int extruder = 0;
// Infill pattern, adjusted for the density etc.
InfillPattern pattern;
InfillPattern pattern = InfillPattern(0);
// FillBase
// in unscaled coordinates
coordf_t spacing;
coordf_t spacing = 0.;
// infill / perimeter overlap, in unscaled coordinates
coordf_t overlap;
coordf_t overlap = 0.;
// Angle as provided by the region config, in radians.
float angle;
float angle = 0.f;
// Non-negative for a bridge.
float bridge_angle;
float bridge_angle = 0.f;
// FillParams
float density;
float density = 0.f;
// Don't connect the fill lines around the inner perimeter.
bool dont_connect;
bool dont_connect = false;
// Don't adjust spacing to fill the space evenly.
bool dont_adjust;
bool dont_adjust = false;
// width, height of extrusion, nozzle diameter, is bridge
// For the output, for fill generator.
Flow flow;
Flow flow = Flow(0.f, 0.f, 0.f, false);
// For the output
ExtrusionRole extrusion_role;
ExtrusionRole extrusion_role = ExtrusionRole(0);
// Various print settings?
// Index of this entry in a linear vector.
size_t idx;
size_t idx = 0;
bool operator<(const SurfaceFillParams &rhs) const {

View File

@ -246,7 +246,7 @@ static void extract_model_from_archive(
sscanf(normal_buf[2], "%f", &facet.normal(2)) != 1) {
// Normal was mangled. Maybe denormals or "not a number" were stored?
// Just reset the normal and silently ignore it.
memset(&facet.normal, 0, sizeof(facet.normal));
facet.normal = stl_normal::Zero();
}
facets.emplace_back(facet);
}

View File

@ -1462,7 +1462,7 @@ stl_stats ModelObject::get_object_stl_stats() const
return this->volumes[0]->mesh().stl.stats;
stl_stats full_stats;
memset(&full_stats, 0, sizeof(stl_stats));
full_stats.volume = 0.f;
// fill full_stats from all objet's meshes
for (ModelVolume* volume : this->volumes)