diff --git a/source/Cosmos.System2/Graphics/VBECanvas.cs b/source/Cosmos.System2/Graphics/VBECanvas.cs index a5cd53dc70..7088967114 100644 --- a/source/Cosmos.System2/Graphics/VBECanvas.cs +++ b/source/Cosmos.System2/Graphics/VBECanvas.cs @@ -285,6 +285,10 @@ public override void DrawArray(int[] aColors, int aX, int aY, int aWidth, int aH { for (int i = 0; i < aHeight; i++) { + if (i >= mode.Height) + { + return; + } int destinationIndex = (aY + i) * (int)mode.Width + aX; driver.CopyVRAM(destinationIndex, aColors, i * aWidth, aWidth); } @@ -294,6 +298,10 @@ public override void DrawArray(int[] aColors, int aX, int aY, int aWidth, int aH { for (int i = 0; i < aHeight; i++) { + if (i >= mode.Height) + { + return; + } int destinationIndex = (aY + i) * (int)mode.Width + aX; driver.CopyVRAM(destinationIndex, aColors, i * aWidth + startIndex, aWidth); } @@ -458,15 +466,16 @@ public override Bitmap GetImage(int x, int y, int width, int height) int endX = Math.Min(x + width, (int)Mode.Width); int endY = Math.Min(y + height, (int)Mode.Height); - int offsetX = Math.Max(0, -x); - int offsetY = Math.Max(0, -y); + int offsetX = Math.Max(0, -x); + int offsetY = Math.Max(0, -y); - int[] rawData = new int[width * height]; + int[] rawData = new int[width * height]; for (int posy = startY; posy < endY; posy++) { int srcOffset = posy * (int)Mode.Width + startX; - int destOffset = (posy - startY) * width; + int destOffset = (posy - startY + offsetY) * width + offsetX; + driver.GetVRAM(srcOffset, rawData, destOffset, endX - startX); }