Skip to content

Commit

Permalink
inlined output function so dtor/ctor matches between vs2017 and vs2019 (
Browse files Browse the repository at this point in the history
  • Loading branch information
CedricGuillemet authored and PolygonalSun committed Mar 11, 2021
1 parent feefb41 commit 4c213ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
31 changes: 30 additions & 1 deletion GLTFSDK/Inc/GLTFSDK/BufferBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <GLTFSDK/GLTF.h>
#include <GLTFSDK/Document.h>

#include <functional>

Expand Down Expand Up @@ -72,7 +73,35 @@ namespace Microsoft

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

void Output(Document& gltfDocument);
// This method moved from the .cpp to the header because
// When this library is built with VS2017 and used in an executable built with VS2019
// an unordered_map issue ( see https://docs.microsoft.com/en-us/cpp/overview/cpp-conformance-improvements?view=msvc-160 )
// makes the destruction to perform an underflow.
// To fix the issue, the code here is inlined so it gets compiled and linked with VS2019.
// So only 1 version of std::unordered_map binary code is generated.
void Output(Document& gltfDocument)
{
for (auto& buffer : m_buffers.Elements())
{
gltfDocument.buffers.Append(std::move(buffer), AppendIdPolicy::ThrowOnEmpty);
}

m_buffers.Clear();

for (auto& bufferView : m_bufferViews.Elements())
{
gltfDocument.bufferViews.Append(std::move(bufferView), AppendIdPolicy::ThrowOnEmpty);
}

m_bufferViews.Clear();

for (auto& accessor : m_accessors.Elements())
{
gltfDocument.accessors.Append(std::move(accessor), AppendIdPolicy::ThrowOnEmpty);
}

m_accessors.Clear();
}

const Buffer& GetCurrentBuffer() const;
const BufferView& GetCurrentBufferView() const;
Expand Down
24 changes: 0 additions & 24 deletions GLTFSDK/Source/BufferBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,6 @@ void BufferBuilder::AddAccessors(const void* data, size_t count, size_t byteStri
}
}

void BufferBuilder::Output(Document& gltfDocument)
{
for (auto& buffer : m_buffers.Elements())
{
gltfDocument.buffers.Append(std::move(buffer), AppendIdPolicy::ThrowOnEmpty);
}

m_buffers.Clear();

for (auto& bufferView : m_bufferViews.Elements())
{
gltfDocument.bufferViews.Append(std::move(bufferView), AppendIdPolicy::ThrowOnEmpty);
}

m_bufferViews.Clear();

for (auto& accessor : m_accessors.Elements())
{
gltfDocument.accessors.Append(std::move(accessor), AppendIdPolicy::ThrowOnEmpty);
}

m_accessors.Clear();
}

const Buffer& BufferBuilder::GetCurrentBuffer() const
{
return m_buffers.Back();
Expand Down

0 comments on commit 4c213ea

Please sign in to comment.