Abort calls in AssImp, which occur when an assert is hit in builds th… (#1012)

* Abort calls in AssImp, which occur when an assert is hit in builds that have asserts enabled (like debug) no longer generate a popup. Instead, they are captured as errors and an asset processing failure.

* Added missing include

* Added check for _WRITE_ABORT_MSG, so platforms that don't have it but have signals enabled (Linux profile) compile correctly
main
AMZN-stankowi 5 years ago committed by GitHub
parent b80e5c3e1f
commit 1369e29c73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,6 +17,13 @@
#include <assimp/scene.h> #include <assimp/scene.h>
#include <assimp/postprocess.h> #include <assimp/postprocess.h>
#if AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
#include <csignal>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#endif // AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
namespace AZ namespace AZ
{ {
namespace AssImpSDKWrapper namespace AssImpSDKWrapper
@ -34,10 +41,31 @@ namespace AZ
{ {
} }
#if AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
void signal_handler(int signal)
{
AZ_TracePrintf(
SceneAPI::Utilities::ErrorWindow,
"Failed to import scene with Asset Importer library. An %s has occured in the library, this scene file cannot be parsed by the library.",
signal == SIGABRT ? "assert" : "unknown error");
}
#endif // AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
bool AssImpSceneWrapper::LoadSceneFromFile(const char* fileName) bool AssImpSceneWrapper::LoadSceneFromFile(const char* fileName)
{ {
AZ_TracePrintf(SceneAPI::Utilities::LogWindow, "AssImpSceneWrapper::LoadSceneFromFile %s", fileName); AZ_TracePrintf(SceneAPI::Utilities::LogWindow, "AssImpSceneWrapper::LoadSceneFromFile %s", fileName);
AZ_TraceContext("Filename", fileName); AZ_TraceContext("Filename", fileName);
#if AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
// Turn off the abort popup because it can disrupt automation.
// AssImp calls abort when asserts are enabled, and an assert is encountered.
#ifdef _WRITE_ABORT_MSG
_set_abort_behavior(0, _WRITE_ABORT_MSG);
#endif // #ifdef _WRITE_ABORT_MSG
// Instead, capture any calls to abort with a signal handler, and report them.
auto previous_handler = std::signal(SIGABRT, signal_handler);
#endif // AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
// aiProcess_JoinIdenticalVertices is not enabled because O3DE has a mesh optimizer that also does this, // aiProcess_JoinIdenticalVertices is not enabled because O3DE has a mesh optimizer that also does this,
// this flag is disabled to keep AssImp output similar to FBX SDK to reduce downstream bugs for the initial AssImp release. // this flag is disabled to keep AssImp output similar to FBX SDK to reduce downstream bugs for the initial AssImp release.
// There's currently a minimum of properties and flags set to maximize compatibility with the existing node graph. // There's currently a minimum of properties and flags set to maximize compatibility with the existing node graph.
@ -49,6 +77,15 @@ namespace AZ
| aiProcess_LimitBoneWeights //Limits the number of bones that can affect a vertex to a maximum value | aiProcess_LimitBoneWeights //Limits the number of bones that can affect a vertex to a maximum value
//dropping the least important and re-normalizing //dropping the least important and re-normalizing
| aiProcess_GenNormals); //Generate normals for meshes | aiProcess_GenNormals); //Generate normals for meshes
#if AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
// Reset abort behavior for anything else that may call abort.
std::signal(SIGABRT, previous_handler);
#ifdef _WRITE_ABORT_MSG
_set_abort_behavior(1, _WRITE_ABORT_MSG);
#endif // #ifdef _WRITE_ABORT_MSG
#endif // AZ_TRAIT_COMPILER_SUPPORT_CSIGNAL
if (!m_assImpScene) if (!m_assImpScene)
{ {
AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to import Asset Importer Scene. Error returned: %s", m_importer.GetErrorString()); AZ_TracePrintf(SceneAPI::Utilities::ErrorWindow, "Failed to import Asset Importer Scene. Error returned: %s", m_importer.GetErrorString());

Loading…
Cancel
Save