mojira.dev
MC-306571

CommandEncoder.copyTextureToBuffer has incorrect parameter validation statements

The function is:

public void copyTextureToBuffer(
      final GpuTexture source,
      final GpuBuffer destination,
      final long offset,
      final Runnable callback,
      final int mipLevel,
      final int x,
      final int y,
      final int width,
      final int height
   )

And an if in it:

    if (source.getWidth(mipLevel) * source.getHeight(mipLevel) * source.getFormat().pixelSize() + offset > destination.size()) {
            throw new IllegalArgumentException(
               "Buffer of size "
                  + destination.size()
                  + " is not large enough to hold "
                  + width
                  + "x"
                  + height
                  + " pixels ("
                  + source.getFormat().pixelSize()
                  + " bytes each) starting from offset "
                  + offset
            );
         }

I think this is incorrect. This makes me can’t copy a subimage from the GpuTexture into the GpuBuffer, unless its size is enough for entire GpuTexture. Not sure about its usages in Minecraft.

My suggestion (untested):

(long)width * (long)height * source.getFormat().pixelSize() + offset > destination.size()

Comments 0

No comments.

KonohaScarlet

(Unassigned)

Plausible

(Unassigned)

26.1 Snapshot 9

Retrieved