Skip to content

Commit eea129f

Browse files
and this is why, kids, you should always use explicit when declaring a constructor from an object of an unrelated type
1 parent aebaa24 commit eea129f

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

include/nbl/asset/utils/CDirQuantCacheBase.h

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@ class CDirQuantCacheBase
4646

4747
Vector8u3() : x(0u),y(0u),z(0u) {}
4848
Vector8u3(const Vector8u3&) = default;
49-
Vector8u3(const core::vectorSIMDu32& val)
49+
explicit Vector8u3(const core::vectorSIMDu32& val)
50+
{
51+
operator=(val);
52+
}
53+
54+
Vector8u3& operator=(const Vector8u3&) = default;
55+
Vector8u3& operator=(const core::vectorSIMDu32& val)
5056
{
5157
x = val.x;
5258
y = val.y;
5359
z = val.z;
60+
return *this;
5461
}
5562

56-
Vector8u3& operator=(const Vector8u3&) = default;
57-
5863
inline core::vectorSIMDu32 getValue() const
5964
{
6065
return core::vectorSIMDu32(x,y,z);
@@ -72,16 +77,21 @@ class CDirQuantCacheBase
7277

7378
Vector8u4() : x(0u),y(0u),z(0u),w(0u) {}
7479
Vector8u4(const Vector8u4&) = default;
75-
Vector8u4(const core::vectorSIMDu32& val)
80+
explicit Vector8u4(const core::vectorSIMDu32& val)
81+
{
82+
operator=(val);
83+
}
84+
85+
Vector8u4& operator=(const Vector8u4&) = default;
86+
Vector8u4& operator=(const core::vectorSIMDu32& val)
7687
{
7788
x = val.x;
7889
y = val.y;
7990
z = val.z;
8091
w = val.w;
92+
return *this;
8193
}
8294

83-
Vector8u4& operator=(const Vector8u4&) = default;
84-
8595
inline core::vectorSIMDu32 getValue() const
8696
{
8797
return core::vectorSIMDu32(x,y,z,w);
@@ -101,13 +111,19 @@ class CDirQuantCacheBase
101111

102112
Vector1010102() : storage(0u) {}
103113
Vector1010102(const Vector1010102&) = default;
104-
Vector1010102(const core::vectorSIMDu32& val)
114+
explicit Vector1010102(const core::vectorSIMDu32& val)
115+
{
116+
operator=(val);
117+
}
118+
119+
Vector1010102& operator=(const Vector1010102&) = default;
120+
Vector1010102& operator=(const core::vectorSIMDu32& val)
105121
{
106122
constexpr auto storageBits = quantizationBits+1u;
107123
storage = val.x|(val.y<<storageBits)|(val.z<<(storageBits*2u));
124+
return *this;
108125
}
109126

110-
Vector1010102& operator=(const Vector1010102&) = default;
111127
inline bool operator<(const Vector1010102& other) const
112128
{
113129
return storage<other.storage;
@@ -136,15 +152,20 @@ class CDirQuantCacheBase
136152

137153
Vector16u3() : x(0u),y(0u),z(0u) {}
138154
Vector16u3(const Vector16u3&) = default;
139-
Vector16u3(const core::vectorSIMDu32& val)
155+
explicit Vector16u3(const core::vectorSIMDu32& val)
156+
{
157+
operator=(val);
158+
}
159+
160+
Vector16u3& operator=(const Vector16u3&) = default;
161+
Vector16u3& operator=(const core::vectorSIMDu32& val)
140162
{
141163
x = val.x;
142164
y = val.y;
143165
z = val.z;
166+
return *this;
144167
}
145168

146-
Vector16u3& operator=(const Vector16u3&) = default;
147-
148169
inline core::vectorSIMDu32 getValue() const
149170
{
150171
return core::vectorSIMDu32(x,y,z);
@@ -162,16 +183,21 @@ class CDirQuantCacheBase
162183

163184
Vector16u4() : x(0u),y(0u),z(0u),w(0u) {}
164185
Vector16u4(const Vector16u4&) = default;
165-
Vector16u4(const core::vectorSIMDu32& val)
186+
explicit Vector16u4(const core::vectorSIMDu32& val)
187+
{
188+
operator=(val);
189+
}
190+
191+
Vector16u4& operator=(const Vector16u4&) = default;
192+
Vector16u4& operator=(const core::vectorSIMDu32& val)
166193
{
167194
x = val.x;
168195
y = val.y;
169196
z = val.z;
170197
w = val.w;
198+
return *this;
171199
}
172200

173-
Vector16u4& operator=(const Vector16u4&) = default;
174-
175201
inline core::vectorSIMDu32 getValue() const
176202
{
177203
return core::vectorSIMDu32(x,y,z,w);

src/nbl/asset/utils/CGeometryCreator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ CGeometryCreator::return_type CGeometryCreator::createCylinderMesh(float radius,
465465
auto vtxBuf = core::make_smart_refctd_ptr<asset::ICPUBuffer>(vtxCnt*sizeof(CylinderVertex));
466466

467467
CylinderVertex* vertices = reinterpret_cast<CylinderVertex*>(vtxBuf->getPointer());
468-
std::fill(vertices, vertices + vtxCnt, CylinderVertex());
468+
for (auto i=0ull; i<vtxCnt; i++)
469+
vertices[i] = CylinderVertex();
469470

470471
const uint32_t halfIx = tesselation;
471472

@@ -528,7 +529,7 @@ CGeometryCreator::return_type CGeometryCreator::createConeMesh( float radius, fl
528529
ConeVertex* baseVertices = vertices;
529530
ConeVertex* apexVertices = vertices + tesselation;
530531

531-
std::fill(vertices,vertices+vtxCnt, ConeVertex(core::vectorSIMDf(0.f),core::vectorSIMDu32(0u),colorBottom));
532+
std::fill(vertices,vertices+vtxCnt, ConeVertex(core::vectorSIMDf(0.f),{},colorBottom));
532533
CQuantNormalCache* const quantNormalCache = (meshManipulatorOverride == nullptr) ? defaultMeshManipulator->getQuantNormalCache() : meshManipulatorOverride->getQuantNormalCache();
533534

534535
const float step = (2.f*core::PI<float>()) / tesselation;

src/nbl/asset/utils/CGeometryCreator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class CGeometryCreator : public IGeometryCreator
7272

7373
struct CylinderVertex
7474
{
75-
CylinderVertex() : pos{0.f, 0.f, 0.f}, color{0u, 0u, 0u, 0u}, uv{0.f, 0.f}, normal{0u} {}
75+
CylinderVertex() : pos{0.f, 0.f, 0.f}, color{0u, 0u, 0u, 0u}, uv{0.f, 0.f}, normal() {}
7676

7777
float pos[3];
7878
uint8_t color[4];

0 commit comments

Comments
 (0)