Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap rendering operations inside a try-catch #47

Merged
merged 2 commits into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ class HtmlCanvas(val settings: Canvas.Settings) extends LowLevelCanvas {
buffer.data(baseAddr + 2) = c.b
}

def putPixel(x: Int, y: Int, color: Color): Unit =
def putPixel(x: Int, y: Int, color: Color): Unit = try {
if (settings.scale == 1) putPixelUnscaled(x, y, color)
else putPixelScaled(x, y, color)
} catch { case _: Throwable => () }

def getBackbufferPixel(x: Int, y: Int): Color = {
val baseAddr = 4 * (y * settings.scale * settings.scaledWidth + (x * settings.scale))
Expand Down Expand Up @@ -123,10 +124,10 @@ class HtmlCanvas(val settings: Canvas.Settings) extends LowLevelCanvas {
}
}
if (resources.contains(Canvas.Resource.Keyboard)) {
keyboardInput = keyboardInput.clearPressRelease
keyboardInput = keyboardInput.clearPressRelease()
}
if (resources.contains(Canvas.Resource.Pointer)) {
pointerInput = pointerInput.clearPressRelease
pointerInput = pointerInput.clearPressRelease()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ class AwtCanvas(val settings: Canvas.Settings) extends LowLevelCanvas {
y * settings.scaledWidth + x % settings.scaledWidth,
c.argb)

def putPixel(x: Int, y: Int, color: Color): Unit =
def putPixel(x: Int, y: Int, color: Color): Unit = try {
if (settings.scale == 1) putPixelUnscaled(x, y, color)
else putPixelScaled(x, y, color)
} catch { case _: Throwable => () }

def getBackbufferPixel(x: Int, y: Int): Color = {
Color.fromRGB(javaCanvas.imagePixels.getElem(y * settings.scale * settings.scaledWidth + (x * settings.scale)))
Expand Down Expand Up @@ -92,12 +93,12 @@ class AwtCanvas(val settings: Canvas.Settings) extends LowLevelCanvas {
}
}

def redraw(): Unit = {
def redraw(): Unit = try {
val g = javaCanvas.buffStrategy.getDrawGraphics()
g.drawImage(javaCanvas.image, 0, 0, settings.scaledWidth, settings.scaledHeight, javaCanvas)
g.dispose()
javaCanvas.buffStrategy.show()
}
} catch { case _: Throwable => () }

def getKeyboardInput(): KeyboardInput = keyListener.getKeyboardInput()
def getPointerInput(): PointerInput = mouseListener.getPointerInput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ class SdlCanvas(val settings: Canvas.Settings) extends LowLevelCanvas {
surface.pixels(baseAddr + 2) = c.r.toByte
}

def putPixel(x: Int, y: Int, color: Color): Unit =
def putPixel(x: Int, y: Int, color: Color): Unit = try {
if (settings.scale == 1) putPixelUnscaled(x, y, color)
else putPixelScaled(x, y, color)
} catch { case _: Throwable => () }

def getBackbufferPixel(x: Int, y: Int): Color = {
// Assuming a BGRA surface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object CanvasIO {
* This operation can be perfomance intensive, so it might be worthwile
* to implement this operation on the application code.
*/
val getBackbuffer: CanvasIO[Vector[Vector[Color]]] = accessCanvas(_.getBackbuffer)
val getBackbuffer: CanvasIO[Vector[Vector[Color]]] = accessCanvas(_.getBackbuffer())

/** Gets the current keyboard input. */
val getKeyboardInput: CanvasIO[KeyboardInput] = accessCanvas(_.getKeyboardInput())
Expand Down