Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-122640 fix crash with deactivate and console #2268

Merged
merged 5 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 48 additions & 10 deletions lib/mayaUsd/ufe/UsdUIInfoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void addMetadataCount(
addMetadataStrings(refs.size(), tooltip, needComma, singular, plural);
}
}

} // namespace

namespace MAYAUSD_NS_DEF {
Expand All @@ -76,13 +77,55 @@ namespace ufe {
UsdUIInfoHandler::UsdUIInfoHandler()
: Ufe::UIInfoHandler()
{
// Register a callback to invalidate the invisible color.
fColorChangedCallbackId = MEventMessage::addEventCallback(
"DisplayRGBColorChanged", onColorChanged, reinterpret_cast<void*>(this));

// Immediately update the invisible color to get a starting current value.
updateInvisibleColor();
}

UsdUIInfoHandler::~UsdUIInfoHandler() { }
UsdUIInfoHandler::~UsdUIInfoHandler()
{
// Unregister the callback used to invalidate the invisible color.
if (fColorChangedCallbackId)
MMessage::removeCallback(fColorChangedCallbackId);
}

/*static*/
UsdUIInfoHandler::Ptr UsdUIInfoHandler::create() { return std::make_shared<UsdUIInfoHandler>(); }

void UsdUIInfoHandler::updateInvisibleColor()
{
// Retrieve the invisible color of the outliner.
//
// We *cannot* intialize it in treeViewCellInfo() because
// that function gets called in a paint event and calling
// a command in a painting event can cause a recursive paint
// event if commands echoing is on, which can corrupt the
// Qt paint internal which lead to a crash. Typical symptom
// is that the state variable of the Qt paint engine becomes
// null midway through the repaint.

MDoubleArray color;
MGlobal::executeCommand("displayRGBColor -q \"outlinerInvisibleColor\"", color);

if (color.length() >= 3) {
color.get(fInvisibleColor.data());
fInvisibleColorValid = true;
}
}

/*static*/
void UsdUIInfoHandler::onColorChanged(void* data)
{
UsdUIInfoHandler* infoHandler = reinterpret_cast<UsdUIInfoHandler*>(data);
if (!infoHandler)
return;

infoHandler->updateInvisibleColor();
}

//------------------------------------------------------------------------------
// Ufe::UIInfoHandler overrides
//------------------------------------------------------------------------------
Expand All @@ -98,16 +141,11 @@ bool UsdUIInfoHandler::treeViewCellInfo(const Ufe::SceneItem::Ptr& item, Ufe::Ce
if (!usdItem->prim().IsActive()) {
changed = true;
info.fontStrikeout = true;
MDoubleArray outlinerInvisibleColor;
if (MGlobal::executeCommand(
"displayRGBColor -q \"outlinerInvisibleColor\"", outlinerInvisibleColor)
&& (outlinerInvisibleColor.length() == 3)) {
double rgb[3];
outlinerInvisibleColor.get(rgb);
if (fInvisibleColorValid) {
info.textFgColor.set(
static_cast<float>(rgb[0]),
static_cast<float>(rgb[1]),
static_cast<float>(rgb[2]));
static_cast<float>(fInvisibleColor[0]),
static_cast<float>(fInvisibleColor[1]),
static_cast<float>(fInvisibleColor[2]));
} else {
info.textFgColor.set(0.403922f, 0.403922f, 0.403922f);
}
Expand Down
14 changes: 14 additions & 0 deletions lib/mayaUsd/ufe/UsdUIInfoHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

#include <mayaUsd/base/api.h>

#include <maya/MEventMessage.h>
#include <ufe/uiInfoHandler.h>

#include <array>

namespace MAYAUSD_NS_DEF {
namespace ufe {

Expand All @@ -47,6 +50,17 @@ class MAYAUSD_CORE_PUBLIC UsdUIInfoHandler : public Ufe::UIInfoHandler
Ufe::UIInfoHandler::Icon treeViewIcon(const Ufe::SceneItem::Ptr& item) const override;
std::string treeViewTooltip(const Ufe::SceneItem::Ptr& item) const override;
std::string getLongRunTimeLabel() const override;

private:
void updateInvisibleColor();

// Note: the on-color-changed callback function is declared taking a void pointer
// to be compatible with MMessage callback API.
static void onColorChanged(void*);

std::array<double, 3> fInvisibleColor;
bool fInvisibleColorValid = false;
MCallbackId fColorChangedCallbackId = 0;
}; // UsdUIInfoHandler

} // namespace ufe
Expand Down