[ue4] Closes #1425, scratch buffer in renderer would eventually also turn into output buffer of clipper due to incorrect assignment of array.

This commit is contained in:
badlogic 2019-08-02 16:16:21 +02:00
parent 083ef01160
commit 706c01de00
2 changed files with 14 additions and 12 deletions

View File

@ -230,7 +230,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle
unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 }; unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 };
for (int i = 0; i < (int)Skeleton->getSlots().size(); ++i) { for (int i = 0; i < (int)Skeleton->getSlots().size(); ++i) {
Vector<float> &attachmentVertices = worldVertices; Vector<float> *attachmentVertices = &worldVertices;
unsigned short* attachmentIndices = nullptr; unsigned short* attachmentIndices = nullptr;
int numVertices; int numVertices;
int numIndices; int numIndices;
@ -250,7 +250,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle
RegionAttachment* regionAttachment = (RegionAttachment*)attachment; RegionAttachment* regionAttachment = (RegionAttachment*)attachment;
attachmentColor.set(regionAttachment->getColor()); attachmentColor.set(regionAttachment->getColor());
attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject(); attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject();
regionAttachment->computeWorldVertices(slot->getBone(), attachmentVertices, 0, 2); regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2);
attachmentIndices = quadIndices; attachmentIndices = quadIndices;
attachmentUvs = regionAttachment->getUVs().buffer(); attachmentUvs = regionAttachment->getUVs().buffer();
numVertices = 4; numVertices = 4;
@ -260,7 +260,7 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle
MeshAttachment* mesh = (MeshAttachment*)attachment; MeshAttachment* mesh = (MeshAttachment*)attachment;
attachmentColor.set(mesh->getColor()); attachmentColor.set(mesh->getColor());
attachmentAtlasRegion = (AtlasRegion*)mesh->getRendererObject(); 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(); attachmentIndices = mesh->getTriangles().buffer();
attachmentUvs = mesh->getUVs().buffer(); attachmentUvs = mesh->getUVs().buffer();
numVertices = mesh->getWorldVerticesLength() >> 1; numVertices = mesh->getWorldVerticesLength() >> 1;
@ -299,8 +299,8 @@ void SSpineWidget::UpdateMesh(int32 LayerId, FSlateWindowElementList& OutDrawEle
} }
if (clipper.isClipping()) { if (clipper.isClipping()) {
clipper.clipTriangles(attachmentVertices.buffer(), attachmentIndices, numIndices, attachmentUvs, 2); clipper.clipTriangles(attachmentVertices->buffer(), attachmentIndices, numIndices, attachmentUvs, 2);
attachmentVertices = clipper.getClippedVertices(); attachmentVertices = &clipper.getClippedVertices();
numVertices = clipper.getClippedVertices().size() >> 1; numVertices = clipper.getClippedVertices().size() >> 1;
attachmentIndices = clipper.getClippedTriangles().buffer(); attachmentIndices = clipper.getClippedTriangles().buffer();
numIndices = clipper.getClippedTriangles().size(); 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 dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f;
float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f; float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f;
float* verticesPtr = attachmentVertices->buffer();
for (int j = 0; j < numVertices << 1; j += 2) { for (int j = 0; j < numVertices << 1; j += 2) {
colors.Add(FColor(r, g, b, a)); colors.Add(FColor(r, g, b, a));
darkColors.Add(FVector(dr, dg, db)); 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])); uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1]));
} }

View File

@ -206,7 +206,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 }; unsigned short quadIndices[] = { 0, 1, 2, 0, 2, 3 };
for (size_t i = 0; i < Skeleton->getSlots().size(); ++i) { for (size_t i = 0; i < Skeleton->getSlots().size(); ++i) {
Vector<float> &attachmentVertices = worldVertices; Vector<float> *attachmentVertices = &worldVertices;
unsigned short* attachmentIndices = nullptr; unsigned short* attachmentIndices = nullptr;
int numVertices; int numVertices;
int numIndices; int numIndices;
@ -237,7 +237,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
attachmentColor.set(regionAttachment->getColor()); attachmentColor.set(regionAttachment->getColor());
attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject(); attachmentAtlasRegion = (AtlasRegion*)regionAttachment->getRendererObject();
regionAttachment->computeWorldVertices(slot->getBone(), attachmentVertices, 0, 2); regionAttachment->computeWorldVertices(slot->getBone(), *attachmentVertices, 0, 2);
attachmentIndices = quadIndices; attachmentIndices = quadIndices;
attachmentUvs = regionAttachment->getUVs().buffer(); attachmentUvs = regionAttachment->getUVs().buffer();
numVertices = 4; numVertices = 4;
@ -253,7 +253,7 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
attachmentColor.set(mesh->getColor()); attachmentColor.set(mesh->getColor());
attachmentAtlasRegion = (AtlasRegion*)mesh->getRendererObject(); 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(); attachmentIndices = mesh->getTriangles().buffer();
attachmentUvs = mesh->getUVs().buffer(); attachmentUvs = mesh->getUVs().buffer();
numVertices = mesh->getWorldVerticesLength() >> 1; numVertices = mesh->getWorldVerticesLength() >> 1;
@ -291,8 +291,8 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
} }
if (clipper.isClipping()) { if (clipper.isClipping()) {
clipper.clipTriangles(attachmentVertices.buffer(), attachmentIndices, numIndices, attachmentUvs, 2); clipper.clipTriangles(attachmentVertices->buffer(), attachmentIndices, numIndices, attachmentUvs, 2);
attachmentVertices = clipper.getClippedVertices(); attachmentVertices = &clipper.getClippedVertices();
numVertices = clipper.getClippedVertices().size() >> 1; numVertices = clipper.getClippedVertices().size() >> 1;
attachmentIndices = clipper.getClippedTriangles().buffer(); attachmentIndices = clipper.getClippedTriangles().buffer();
numIndices = clipper.getClippedTriangles().size(); numIndices = clipper.getClippedTriangles().size();
@ -317,10 +317,11 @@ void USpineSkeletonRendererComponent::UpdateMesh(Skeleton* Skeleton) {
float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f; float dg = slot->hasDarkColor() ? slot->getDarkColor().g : 0.0f;
float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f; float db = slot->hasDarkColor() ? slot->getDarkColor().b : 0.0f;
float* verticesPtr = attachmentVertices->buffer();
for (int j = 0; j < numVertices << 1; j += 2) { for (int j = 0; j < numVertices << 1; j += 2) {
colors.Add(FColor(r, g, b, a)); colors.Add(FColor(r, g, b, a));
darkColors.Add(FVector(dr, dg, db)); 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)); normals.Add(FVector(0, -1, 0));
uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1])); uvs.Add(FVector2D(attachmentUvs[j], attachmentUvs[j + 1]));
} }