Texture.Apply() Crashes at Resolutions under 1920x1080

So, this is a bug that is, I must admit, “weird as hell”. I have a system set up for taking a screenshot of the scene.

My code is very small, it is these few lines:

Texture2D result;
            result = new Texture2D(Mathf.RoundToInt(captureZone.width) + destX,
                        Mathf.RoundToInt(captureZone.height) + destY,
                        TextureFormat.RGB24, false);

            result.ReadPixels(captureZone, destX, destY, false);
            result.Apply();

            return result;

Now, I’m using this to apply an effect on my screen when I pause the game. I’m capturing the screen once when pause is pressed, which is fine. I then draw that captured screen with a blur effect using Graphics.DrawTexture at a quarter its original scale. I then capture this into another texture, and draw it again to the entire screen, with the same blur effect applied again (this had minimal performance impact and allowed me to apply another blur). I then attempt to capture this last image one last time, so I can draw it directly to the screen without having to apply the filter every frame.

It is this last capture that causes problems. It is using exactly the same code as the first capture (namely, running the above code with the captureZone set to a rectangle at (0,0), spanning to Screen.width and Screen.height, and with destX and destY both set to 0. This works fine in the editor, and when I run the external build at a resolution of 1920x1080.

If I run it at any other resolution, however (regardless of aspect ratio), it immediately freezes. I have probed as much as I can and have found that the line:

result.Apply();

is the one that is freezing the application. The build’s log does not display any error messages.

Run on another computer, however, it all seems to work. I am somewhat concerned by this issue, as it seems completely nonsensical, and I have no clue what could be causing it. If anyone has any ideas, please don’t hesitate to let me know!

I fixed it! Not sure what the original bug was, but after shuffling it around a bit, I discovered that the issue was attempting to read a rectangle from the screen that had non-integer width and/or height. A simple call to RoundToInt fixed it perfectly.