From 706c01de00adbf409d85b2b6e1ffc0ee96ff0d93 Mon Sep 17 00:00:00 2001 From: badlogic Date: Fri, 2 Aug 2019 16:16:21 +0200 Subject: [PATCH] [ue4] Closes #1425, scratch buffer in renderer would eventually also turn into output buffer of clipper due to incorrect assignment of array. --- .../Source/SpinePlugin/Private/SSpineWidget.cpp | 13 +++++++------ .../Private/SpineSkeletonRendererComponent.cpp | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp index 093e72d24..bf1d8d8fb 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SSpineWidget.cpp @@ -230,7 +230,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 }; for (int i = 0; i < (int)Skeleton->getSlots().size(); ++i) { - Vector &attachmentVertices = worldVertices; + Vector *attachmentVertices = &worldVertices; unsigned short* attachmentIndices = nullptr; int numVertices; int numIndices; @@ -250,7 +250,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle RegionAttachment* regionAttachment = (RegionAttachment*)attachment; attachmentColor.set(regionAttachment->getColor()); attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject(); - regionAttachment->computeWorldVertices(slot->getBone(), attachmentVertices, 0, 2); + regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2); attachmentIndices = quadIndices; attachmentUvs = regionAttachment->getUVs().buffer(); numVertices = 4; @@ -260,7 +260,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle MeshAttachment* mesh = (MeshAttachment*)attachment; attachmentColor.set(mesh->getColor()); attachmentAtlasRegion = (AtlasRegion*)mesh->getRendererObject(); - mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices, 0, 2); + mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), *attachmentVertices, 0, 2); attachmentIndices = mesh->getTriangles().buffer(); attachmentUvs = mesh->getUVs().buffer(); numVertices = mesh->getWorldVerticesLength() >> 1; @@ -299,8 +299,8 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle } if (clipper.isClipping()) { - clipper.clipTriangles(attachmentVertices.buffer(), attachmentIndices, numIndices, attachmentUvs, 2); - attachmentVertices = clipper.getClippedVertices(); + clipper.clipTriangles(attachmentVertices->buffer(), attachmentIndices, numIndices, attachmentUvs, 2); + attachmentVertices = &clipper.getClippedVertices(); numVertices = clipper.getClippedVertices().size() >> 1; attachmentIndices = clipper.getClippedTriangles().buffer(); numIndices = clipper.getClippedTriangles().size(); @@ -323,10 +323,11 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f; float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f; + float* verticesPtr = attachmentVertices->buffer(); for (int j = 0; j < numVertices << 1; j += 2) { colors.Add(FColor(r, g, b, a)); darkColors.Add(FVector(dr, dg, db)); - vertices.Add(FVector(attachmentVertices[j], -attachmentVertices[j + 1], depthOffset)); + vertices.Add(FVector(verticesPtr[j], -verticesPtr[j + 1], depthOffset)); uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1])); } diff --git a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp index 2df45a985..820766bb7 100644 --- a/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp +++ b/spine-ue4/Plugins/SpinePlugin/Source/SpinePlugin/Private/SpineSkeletonRendererComponent.cpp @@ -206,7 +206,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) { unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 }; for (size_t i = 0; i < Skeleton->getSlots().size(); ++i) { - Vector &attachmentVertices = worldVertices; + Vector *attachmentVertices = &worldVertices; unsigned short* attachmentIndices = nullptr; int numVertices; int numIndices; @@ -237,7 +237,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) { attachmentColor.set(regionAttachment->getColor()); attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject(); - regionAttachment->computeWorldVertices(slot->getBone(), attachmentVertices, 0, 2); + regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2); attachmentIndices = quadIndices; attachmentUvs = regionAttachment->getUVs().buffer(); numVertices = 4; @@ -253,7 +253,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) { attachmentColor.set(mesh->getColor()); attachmentAtlasRegion = (AtlasRegion*)mesh->getRendererObject(); - mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), attachmentVertices, 0, 2); + mesh->computeWorldVertices(*slot, 0, mesh->getWorldVerticesLength(), *attachmentVertices, 0, 2); attachmentIndices = mesh->getTriangles().buffer(); attachmentUvs = mesh->getUVs().buffer(); numVertices = mesh->getWorldVerticesLength() >> 1; @@ -291,8 +291,8 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) { } if (clipper.isClipping()) { - clipper.clipTriangles(attachmentVertices.buffer(), attachmentIndices, numIndices, attachmentUvs, 2); - attachmentVertices = clipper.getClippedVertices(); + clipper.clipTriangles(attachmentVertices->buffer(), attachmentIndices, numIndices, attachmentUvs, 2); + attachmentVertices = &clipper.getClippedVertices(); numVertices = clipper.getClippedVertices().size() >> 1; attachmentIndices = clipper.getClippedTriangles().buffer(); numIndices = clipper.getClippedTriangles().size(); @@ -317,10 +317,11 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) { float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f; float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f; + float* verticesPtr = attachmentVertices->buffer(); for (int j = 0; j < numVertices << 1; j += 2) { colors.Add(FColor(r, g, b, a)); darkColors.Add(FVector(dr, dg, db)); - vertices.Add(FVector(attachmentVertices[j], depthOffset, attachmentVertices[j + 1])); + vertices.Add(FVector(verticesPtr[j], depthOffset, verticesPtr[j + 1])); normals.Add(FVector(0, -1, 0)); uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1])); }