Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB authored and m0dB committed Oct 20, 2024
1 parent cbd759d commit 212769b
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 27 deletions.
5 changes: 5 additions & 0 deletions src/rendergraph/common/rendergraph/geometrynode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class GeometryNode;
class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode,
public rendergraph::TreeNode {
public:
using rendergraph::TreeNode::appendChildNode;
using rendergraph::TreeNode::firstChild;
using rendergraph::TreeNode::lastChild;
using rendergraph::TreeNode::nextSibling;
using rendergraph::TreeNode::removeChildNode;
GeometryNode();

template<class T_Material>
Expand Down
1 change: 1 addition & 0 deletions src/rendergraph/common/rendergraph/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class rendergraph::Node : public rendergraph::BaseNode, public rendergraph::Tree
using rendergraph::TreeNode::appendChildNode;
using rendergraph::TreeNode::firstChild;
using rendergraph::TreeNode::lastChild;
using rendergraph::TreeNode::nextSibling;
using rendergraph::TreeNode::removeChildNode;
Node();
};
4 changes: 4 additions & 0 deletions src/rendergraph/common/rendergraph/opacitynode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ class rendergraph::OpacityNode : public rendergraph::BaseOpacityNode,
public rendergraph::TreeNode {
public:
using rendergraph::TreeNode::appendChildNode;
using rendergraph::TreeNode::firstChild;
using rendergraph::TreeNode::lastChild;
using rendergraph::TreeNode::nextSibling;
using rendergraph::TreeNode::removeChildNode;
OpacityNode();
};
2 changes: 1 addition & 1 deletion src/rendergraph/common/rendergraph/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class rendergraph::Texture {
qint64 comparisonKey() const;

private:
std::unique_ptr<BaseTexture> m_pTexture{};
const std::unique_ptr<BaseTexture> m_pTexture{};
};
4 changes: 1 addition & 3 deletions src/rendergraph/common/rendergraph/treenode.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class TreeNode;

class rendergraph::TreeNode {
public:
TreeNode(rendergraph::BaseNode* pBackendNode)
: m_pBackendNode(pBackendNode) {
}
TreeNode(rendergraph::BaseNode* pBackendNode);
virtual ~TreeNode();

void appendChildNode(std::unique_ptr<TreeNode>&& pChild);
Expand Down
8 changes: 6 additions & 2 deletions src/rendergraph/opengl/treenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

using namespace rendergraph;

void TreeNode::setUsePreprocess(bool value) {
backendNode()->setUsePreprocessFlag(value);
TreeNode::TreeNode(rendergraph::BaseNode* pBackendNode)
: m_pBackendNode(pBackendNode) {
}

TreeNode::~TreeNode() {
}

void TreeNode::setUsePreprocess(bool value) {
backendNode()->setUsePreprocessFlag(value);
}

void TreeNode::onAppendChildNode(TreeNode* pChild) {
if (backendNode()->engine()) {
backendNode()->engine()->add(pChild);
Expand Down
6 changes: 4 additions & 2 deletions src/rendergraph/scenegraph/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

using namespace rendergraph;

Texture::Texture(Context* pContext, const QImage& image) {
Texture::Texture(Context* pContext, const QImage& image)
: m_pTexture{std::unique_ptr<BaseTexture>(pContext->window()
? pContext->window()->createTextureFromImage(image)
: nullptr)} {
VERIFY_OR_DEBUG_ASSERT(pContext->window() != nullptr) {
return;
}
m_pTexture = std::unique_ptr<BaseTexture>(pContext->window()->createTextureFromImage(image));
DEBUG_ASSERT(!m_pTexture->textureSize().isNull());
}

Expand Down
16 changes: 13 additions & 3 deletions src/rendergraph/scenegraph/treenode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@

using namespace rendergraph;

void TreeNode::setUsePreprocess(bool value) {
backendNode()->setFlag(QSGNode::UsePreprocess, value);
TreeNode::TreeNode(rendergraph::BaseNode* pBackendNode)
: m_pBackendNode(pBackendNode) {
m_pBackendNode->setFlag(QSGNode::OwnedByParent, false);
}

TreeNode::~TreeNode() {
m_pFirstChild.release();
m_pNextSibling.release();
}

void TreeNode::setUsePreprocess(bool value) {
backendNode()->setFlag(QSGNode::UsePreprocess, value);
}

void TreeNode::onAppendChildNode(TreeNode* pChild) {
backendNode()->appendChildNode(pChild->backendNode());
auto pThisBackendNode = backendNode();
auto pChildBackendNode = pChild->backendNode();

pThisBackendNode->appendChildNode(pChildBackendNode);

// backendNode()->appendChildNode(pChild->backendNode());
}

void TreeNode::onRemoveChildNode(TreeNode* pChild) {
Expand Down
21 changes: 11 additions & 10 deletions src/waveform/renderers/allshader/waveformrendermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void allshader::WaveformRenderMark::update() {
const double playPosition = m_waveformRenderer->getTruePosSample(positionType);
double nextMarkPosition = std::numeric_limits<double>::max();

TreeNode* pRangeChild = m_pRangeNodesParent->firstChild();
GeometryNode* pRangeChild = static_cast<GeometryNode*>(m_pRangeNodesParent->firstChild());

for (const auto& pMark : std::as_const(m_marks)) {
if (!pMark->isValid()) {
Expand Down Expand Up @@ -262,9 +262,10 @@ void allshader::WaveformRenderMark::update() {

// Reuse, or create new when needed
if (!pRangeChild) {
m_pRangeNodesParent->appendChildNode(std::make_unique<GeometryNode>());
pRangeChild = m_pRangeNodesParent->lastChild();
static_cast<GeometryNode*>(pRangeChild)->initForRectangles<RGBAMaterial>(2);
auto pNode = std::make_unique<GeometryNode>();
pRangeChild = pNode.get();
pRangeChild->initForRectangles<RGBAMaterial>(2);
m_pRangeNodesParent->appendChildNode(std::move(pNode));
}

updateRangeNode(static_cast<GeometryNode*>(pRangeChild),
Expand All @@ -274,7 +275,7 @@ void allshader::WaveformRenderMark::update() {
color);

visible = true;
pRangeChild = pRangeChild->nextSibling();
pRangeChild = static_cast<GeometryNode*>(pRangeChild->nextSibling());
}
}

Expand All @@ -286,11 +287,11 @@ void allshader::WaveformRenderMark::update() {
}

// Remove unused nodes
while (pRangeChild) {
auto pNext = static_cast<GeometryNode*>(pRangeChild->nextSibling());
m_pRangeNodesParent->removeChildNode(pRangeChild);
pRangeChild = pNext;
}
// while (pRangeChild) {
// auto pNext = static_cast<GeometryNode*>(pRangeChild->nextSibling());
// m_pRangeNodesParent->removeChildNode(pRangeChild);
// pRangeChild = pNext;
//}

m_waveformRenderer->setMarkPositions(marksOnScreen);

Expand Down
13 changes: 7 additions & 6 deletions src/waveform/renderers/allshader/waveformrendermarkrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) {
}

void WaveformRenderMarkRange::update() {
TreeNode* pChild = firstChild();
GeometryNode* pChild = static_cast<GeometryNode*>(firstChild());

for (const auto& markRange : m_markRanges) {
// If the mark range is not active we should not draw it.
Expand Down Expand Up @@ -73,12 +73,13 @@ void WaveformRenderMarkRange::update() {
color.setAlphaF(0.3f);

if (!pChild) {
appendChildNode(std::make_unique<GeometryNode>());
pChild = lastChild();
static_cast<GeometryNode*>(pChild)->initForRectangles<UniColorMaterial>(1);
auto pNode = std::make_unique<GeometryNode>();
pChild = pNode.get();
pChild->initForRectangles<UniColorMaterial>(1);
appendChildNode(std::move(pNode));
}

updateNode(static_cast<GeometryNode*>(pChild),
updateNode(pChild,
color,
{static_cast<float>(startPosition), 0.f},
{static_cast<float>(endPosition) + 1.f,
Expand All @@ -87,7 +88,7 @@ void WaveformRenderMarkRange::update() {
pChild = static_cast<GeometryNode*>(pChild->nextSibling());
}
while (pChild) {
auto pNext = pChild->nextSibling();
auto pNext = static_cast<GeometryNode*>(pChild->nextSibling());
removeChildNode(pChild);
pChild = pNext;
}
Expand Down

0 comments on commit 212769b

Please sign in to comment.