From 0e6fea21fcae344f15955e689a59001b27c00540 Mon Sep 17 00:00:00 2001 From: guthadam Date: Wed, 21 Apr 2021 10:30:27 -0500 Subject: [PATCH] ATOM-15221 Material Editor: Capturing trace warnings and errors to display in error message boxes https://jira.agscollab.com/browse/ATOM-15221 --- .../AtomToolsFramework/Debug/TraceRecorder.h | 41 ++++++++++ .../Code/Source/Debug/TraceRecorder.cpp | 66 ++++++++++++++++ .../Code/atomtoolsframework_files.cmake | 2 + .../MaterialDocumentSystemComponent.cpp | 79 +++++++++++++------ 4 files changed, 163 insertions(+), 25 deletions(-) create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Debug/TraceRecorder.h create mode 100644 Gems/Atom/Tools/AtomToolsFramework/Code/Source/Debug/TraceRecorder.cpp diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Debug/TraceRecorder.h b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Debug/TraceRecorder.h new file mode 100644 index 0000000000..acc9d804bf --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Include/AtomToolsFramework/Debug/TraceRecorder.h @@ -0,0 +1,41 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#pragma once + +#include +#include + +namespace AtomToolsFramework +{ + // Records all TraceMessageBus activity to a string + class TraceRecorder + : private AZ::Debug::TraceMessageBus::Handler + { + public: + AZ_TYPE_INFO(AtomToolsFramework::TraceRecorder, "{7B49AFD0-D0AB-4CB7-A4B5-6D88D30DCBFD}"); + + TraceRecorder(); + ~TraceRecorder(); + + ////////////////////////////////////////////////////////////////////////// + // AZ::Debug::TraceMessageBus::Handler overrides... + bool OnAssert(const char* /*message*/) override; + bool OnException(const char* /*message*/) override; + bool OnError(const char* /*window*/, const char* /*message*/) override; + bool OnWarning(const char* /*window*/, const char* /*message*/) override; + bool OnPrintf(const char* /*window*/, const char* /*message*/) override; + ////////////////////////////////////////////////////////////////////////// + + AZStd::string m_messageSink; + }; +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Debug/TraceRecorder.cpp b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Debug/TraceRecorder.cpp new file mode 100644 index 0000000000..3b22c16dcc --- /dev/null +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/Source/Debug/TraceRecorder.cpp @@ -0,0 +1,66 @@ +/* + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or + * its licensors. + * + * For complete copyright and license terms please see the LICENSE at the root of this + * distribution (the "License"). All use of this software is governed by the License, + * or, if provided, by the license below or the license accompanying this file. Do not + * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + */ + +#include + +namespace AtomToolsFramework +{ + TraceRecorder::TraceRecorder() + { + AZ::Debug::TraceMessageBus::Handler::BusConnect(); + } + + TraceRecorder::~TraceRecorder() + { + AZ::Debug::TraceMessageBus::Handler::BusDisconnect(); + } + + bool TraceRecorder::OnAssert(const char* message) + { + m_messageSink += "Assert: "; + m_messageSink += message; + m_messageSink += "\n"; + return false; + } + + bool TraceRecorder::OnException(const char* message) + { + m_messageSink += "Exception: "; + m_messageSink += message; + m_messageSink += "\n"; + return false; + } + + bool TraceRecorder::OnError(const char* /*window*/, const char* message) + { + m_messageSink += "Error: "; + m_messageSink += message; + m_messageSink += "\n"; + return false; + } + + bool TraceRecorder::OnWarning(const char* /*window*/, const char* message) + { + m_messageSink += "Warning: "; + m_messageSink += message; + m_messageSink += "\n"; + return false; + } + + bool TraceRecorder::OnPrintf(const char* /*window*/, const char* message) + { + m_messageSink += message; + m_messageSink += "\n"; + return false; + } + +} // namespace AtomToolsFramework diff --git a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake index 8c0ca71b78..e8539711f7 100644 --- a/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake +++ b/Gems/Atom/Tools/AtomToolsFramework/Code/atomtoolsframework_files.cmake @@ -10,6 +10,7 @@ # set(FILES + Include/AtomToolsFramework/Debug/TraceRecorder.h Include/AtomToolsFramework/DynamicProperty/DynamicProperty.h Include/AtomToolsFramework/DynamicProperty/DynamicPropertyGroup.h Include/AtomToolsFramework/Inspector/InspectorWidget.h @@ -21,6 +22,7 @@ set(FILES Include/AtomToolsFramework/Util/MaterialPropertyUtil.h Include/AtomToolsFramework/Util/Util.h Include/AtomToolsFramework/Viewport/RenderViewportWidget.h + Source/Debug/TraceRecorder.cpp Source/DynamicProperty/DynamicProperty.cpp Source/DynamicProperty/DynamicPropertyGroup.cpp Source/Inspector/InspectorWidget.cpp diff --git a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp index 234afc6e27..7faeca3f27 100644 --- a/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp +++ b/Gems/Atom/Tools/MaterialEditor/Code/Source/Document/MaterialDocumentSystemComponent.cpp @@ -12,32 +12,29 @@ #include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include - +#include +#include #include - +#include +#include +#include #include #include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // disable warnings spawned by QT #include +#include +#include #include #include -#include -#include AZ_POP_DISABLE_WARNING namespace MaterialEditor @@ -212,11 +209,15 @@ namespace MaterialEditor QString("Would you like to reopen the document:\n%1?").arg(documentPath.c_str()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + AtomToolsFramework::TraceRecorder traceRecorder; + bool openResult = false; MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, documentPath); if (!openResult) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be opened:\n%1").arg(documentPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be opened"), + QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); } } @@ -232,11 +233,15 @@ namespace MaterialEditor QString("Would you like to update the document with these changes:\n%1?").arg(documentPath.c_str()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + AtomToolsFramework::TraceRecorder traceRecorder; + bool openResult = false; MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Rebuild); if (!openResult) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be opened:\n%1").arg(documentPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be opened"), + QString("Failed to open: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::CloseDocument, documentId); } } @@ -308,11 +313,15 @@ namespace MaterialEditor } } + AtomToolsFramework::TraceRecorder traceRecorder; + bool closeResult = true; MaterialDocumentRequestBus::EventResult(closeResult, documentId, &MaterialDocumentRequestBus::Events::Close); if (!closeResult) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be closed:\n%1").arg(documentPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be closed"), + QString("Failed to close: \n%1\n\n%2").arg(documentPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); return false; } @@ -370,11 +379,15 @@ namespace MaterialEditor return false; } + AtomToolsFramework::TraceRecorder traceRecorder; + bool result = false; MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::Save); if (!result) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be saved:\n%1").arg(saveMaterialPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be saved"), + QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); return false; } @@ -396,11 +409,15 @@ namespace MaterialEditor return false; } + AtomToolsFramework::TraceRecorder traceRecorder; + bool result = false; MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsCopy, saveMaterialPath); if (!result) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be saved:\n%1").arg(saveMaterialPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be saved"), + QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); return false; } @@ -422,11 +439,15 @@ namespace MaterialEditor return false; } + AtomToolsFramework::TraceRecorder traceRecorder; + bool result = false; MaterialDocumentRequestBus::EventResult(result, documentId, &MaterialDocumentRequestBus::Events::SaveAsChild, saveMaterialPath); if (!result) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be saved:\n%1").arg(saveMaterialPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be saved"), + QString("Failed to save: \n%1\n\n%2").arg(saveMaterialPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); return false; } @@ -476,19 +497,27 @@ namespace MaterialEditor } } + AtomToolsFramework::TraceRecorder traceRecorder; + AZ::Uuid documentId = AZ::Uuid::CreateNull(); MaterialDocumentSystemRequestBus::BroadcastResult(documentId, &MaterialDocumentSystemRequestBus::Events::CreateDocument); if (documentId.IsNull()) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be created:\n%1").arg(requestedPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be created"), + QString("Failed to create: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); return AZ::Uuid::CreateNull(); } + traceRecorder.m_messageSink.clear(); + bool openResult = false; MaterialDocumentRequestBus::EventResult(openResult, documentId, &MaterialDocumentRequestBus::Events::Open, requestedPath); if (!openResult) { - QMessageBox::critical(QApplication::activeWindow(), "Error", QString("Material document could not be opened:\n%1").arg(requestedPath.c_str())); + QMessageBox::critical( + QApplication::activeWindow(), QString("Material document could not be opened"), + QString("Failed to open: \n%1\n\n%2").arg(requestedPath.c_str()).arg(traceRecorder.m_messageSink.c_str())); MaterialDocumentSystemRequestBus::Broadcast(&MaterialDocumentSystemRequestBus::Events::DestroyDocument, documentId); return AZ::Uuid::CreateNull(); }