Fix for ReadMesh error reporting
This commit is contained in:
@@ -118,12 +118,15 @@ namespace WhiteBox
|
||||
stream->Read(size, whiteBoxData.data());
|
||||
|
||||
auto whiteBoxMesh = WhiteBox::Api::CreateWhiteBoxMesh();
|
||||
const bool success = WhiteBox::Api::ReadMesh(*whiteBoxMesh, whiteBoxData);
|
||||
const auto result = WhiteBox::Api::ReadMesh(*whiteBoxMesh, whiteBoxData);
|
||||
|
||||
// if result is not 'Full', then whiteBoxMeshAsset could be empty which is most likely an error
|
||||
// as no data was loaded from the asset, or it was not correctly read in stream->Read(..)
|
||||
const auto success = result == Api::ReadResult::Full;
|
||||
if (success)
|
||||
{
|
||||
whiteBoxMeshAsset->SetMesh(AZStd::move(whiteBoxMesh));
|
||||
whiteBoxMeshAsset->SetWhiteBoxData(whiteBoxData);
|
||||
whiteBoxMeshAsset->SetWhiteBoxData(AZStd::move(whiteBoxData));
|
||||
}
|
||||
|
||||
return success ? AZ::Data::AssetHandler::LoadResult::LoadComplete
|
||||
|
||||
@@ -3403,13 +3403,13 @@ namespace WhiteBox
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ReadMesh(WhiteBoxMesh& whiteBox, const WhiteBoxMeshStream& input)
|
||||
ReadResult ReadMesh(WhiteBoxMesh& whiteBox, const WhiteBoxMeshStream& input)
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzToolsFramework);
|
||||
|
||||
if (input.empty())
|
||||
{
|
||||
return false;
|
||||
return ReadResult::Empty;
|
||||
}
|
||||
|
||||
std::string inputStr;
|
||||
@@ -3423,19 +3423,19 @@ namespace WhiteBox
|
||||
return ReadMesh(whiteBox, whiteBoxStream);
|
||||
}
|
||||
|
||||
bool ReadMesh(WhiteBoxMesh& whiteBox, std::istream& input)
|
||||
ReadResult ReadMesh(WhiteBoxMesh& whiteBox, std::istream& input)
|
||||
{
|
||||
const auto skipws = input.flags() & std::ios_base::skipws;
|
||||
AZ_Assert(skipws == 0, "Input stream must not skip white space characters");
|
||||
|
||||
if (skipws != 0)
|
||||
{
|
||||
return false;
|
||||
return ReadResult::Error;
|
||||
}
|
||||
|
||||
AZStd::lock_guard lg(g_omSerializationLock);
|
||||
OpenMesh::IO::Options options{OpenMesh::IO::Options::FaceTexCoord | OpenMesh::IO::Options::FaceNormal};
|
||||
return OpenMesh::IO::read_mesh(whiteBox.mesh, input, ".om", options);
|
||||
return OpenMesh::IO::read_mesh(whiteBox.mesh, input, ".om", options) ? ReadResult::Full : ReadResult::Error;
|
||||
}
|
||||
|
||||
WhiteBoxMeshPtr CloneMesh(const WhiteBoxMesh& whiteBox)
|
||||
@@ -3449,7 +3449,7 @@ namespace WhiteBox
|
||||
}
|
||||
|
||||
WhiteBoxMeshPtr newMesh = CreateWhiteBoxMesh();
|
||||
if (!ReadMesh(*newMesh, clonedData))
|
||||
if (ReadMesh(*newMesh, clonedData) != ReadResult::Full)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -348,14 +348,14 @@ namespace WhiteBox
|
||||
else
|
||||
{
|
||||
// attempt to load the mesh
|
||||
if (Api::ReadMesh(*m_whiteBox, m_whiteBoxData))
|
||||
const auto result = Api::ReadMesh(*m_whiteBox, m_whiteBoxData);
|
||||
AZ_Error("EditorWhiteBoxComponent", result != WhiteBox::Api::ReadResult::Error, "Error deserializing white box mesh stream");
|
||||
|
||||
// if the read was successful but the byte stream is empty
|
||||
// (there was nothing to load), create a default mesh
|
||||
if (result == Api::ReadResult::Empty)
|
||||
{
|
||||
// if the read was successful but the byte stream is empty
|
||||
// (there was nothing to load), create a default mesh
|
||||
if (m_whiteBoxData.empty())
|
||||
{
|
||||
Api::InitializeAsUnitCube(*m_whiteBox);
|
||||
}
|
||||
Api::InitializeAsUnitCube(*m_whiteBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user