Skip to content

Commit dfce430

Browse files
inlined output function so dtor/ctor matches between vs2017 and vs2019 (#73)
1 parent 9428f11 commit dfce430

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

GLTFSDK/Inc/GLTFSDK/BufferBuilder.h

+30-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#pragma once
55

66
#include <GLTFSDK/GLTF.h>
7+
#include <GLTFSDK/Document.h>
78

89
#include <functional>
910

@@ -72,7 +73,35 @@ namespace Microsoft
7273

7374
void AddAccessors(const void* data, size_t count, size_t byteStride, const AccessorDesc* pDescs, size_t descCount, std::string* pOutIds = nullptr);
7475

75-
void Output(Document& gltfDocument);
76+
// This method moved from the .cpp to the header because
77+
// When this library is built with VS2017 and used in an executable built with VS2019
78+
// an unordered_map issue ( see https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=msvc-160 )
79+
// makes the destruction to perform an underflow.
80+
// To fix the issue, the code here is inlined so it gets compiled and linked with VS2019.
81+
// So only 1 version of std::unordered_map binary code is generated.
82+
void Output(Document& gltfDocument)
83+
{
84+
for (auto& buffer : m_buffers.Elements())
85+
{
86+
gltfDocument.buffers.Append(std::move(buffer), AppendIdPolicy::ThrowOnEmpty);
87+
}
88+
89+
m_buffers.Clear();
90+
91+
for (auto& bufferView : m_bufferViews.Elements())
92+
{
93+
gltfDocument.bufferViews.Append(std::move(bufferView), AppendIdPolicy::ThrowOnEmpty);
94+
}
95+
96+
m_bufferViews.Clear();
97+
98+
for (auto& accessor : m_accessors.Elements())
99+
{
100+
gltfDocument.accessors.Append(std::move(accessor), AppendIdPolicy::ThrowOnEmpty);
101+
}
102+
103+
m_accessors.Clear();
104+
}
76105

77106
const Buffer& GetCurrentBuffer() const;
78107
const BufferView& GetCurrentBufferView() const;

GLTFSDK/Source/BufferBuilder.cpp

-24
Original file line numberDiff line numberDiff line change
@@ -213,30 +213,6 @@ void BufferBuilder::AddAccessors(const void* data, size_t count, size_t byteStri
213213
}
214214
}
215215

216-
void BufferBuilder::Output(Document& gltfDocument)
217-
{
218-
for (auto& buffer : m_buffers.Elements())
219-
{
220-
gltfDocument.buffers.Append(std::move(buffer), AppendIdPolicy::ThrowOnEmpty);
221-
}
222-
223-
m_buffers.Clear();
224-
225-
for (auto& bufferView : m_bufferViews.Elements())
226-
{
227-
gltfDocument.bufferViews.Append(std::move(bufferView), AppendIdPolicy::ThrowOnEmpty);
228-
}
229-
230-
m_bufferViews.Clear();
231-
232-
for (auto& accessor : m_accessors.Elements())
233-
{
234-
gltfDocument.accessors.Append(std::move(accessor), AppendIdPolicy::ThrowOnEmpty);
235-
}
236-
237-
m_accessors.Clear();
238-
}
239-
240216
const Buffer& BufferBuilder::GetCurrentBuffer() const
241217
{
242218
return m_buffers.Back();

0 commit comments

Comments
 (0)