mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Added handling for OOM errors when allocating hologram rendering data. Closes #1105.
This commit is contained in:
parent
d5f1280fc9
commit
7d69f996cb
@ -57,7 +57,18 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
|
|||||||
/** Used to pass the current screen along to call(). */
|
/** Used to pass the current screen along to call(). */
|
||||||
private var hologram: Hologram = null
|
private var hologram: Hologram = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether initialization failed (e.g. due to an out of memory error) and we
|
||||||
|
* should render using the fallback renderer instead.
|
||||||
|
*/
|
||||||
|
private var failed = false
|
||||||
|
|
||||||
override def renderTileEntityAt(te: TileEntity, x: Double, y: Double, z: Double, f: Float) {
|
override def renderTileEntityAt(te: TileEntity, x: Double, y: Double, z: Double, f: Float) {
|
||||||
|
if (failed) {
|
||||||
|
HologramRendererFallback.renderTileEntityAt(te, x, y, z, f)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
|
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
|
||||||
|
|
||||||
hologram = te.asInstanceOf[Hologram]
|
hologram = te.asInstanceOf[Hologram]
|
||||||
@ -142,12 +153,13 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
|
|||||||
}
|
}
|
||||||
|
|
||||||
def draw(glBuffer: Int) {
|
def draw(glBuffer: Int) {
|
||||||
initialize()
|
if (initialize()) {
|
||||||
validate(glBuffer)
|
validate(glBuffer)
|
||||||
publish(glBuffer)
|
publish(glBuffer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def initialize() {
|
private def initialize(): Boolean = !failed && (try {
|
||||||
// First run only, create structure information.
|
// First run only, create structure information.
|
||||||
if (commonBuffer == 0) {
|
if (commonBuffer == 0) {
|
||||||
dataBuffer = BufferUtils.createIntBuffer(hologram.width * hologram.width * hologram.height * 6 * 4 * 2)
|
dataBuffer = BufferUtils.createIntBuffer(hologram.width * hologram.width * hologram.height * 6 * 4 * 2)
|
||||||
@ -222,7 +234,14 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
|
|||||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, commonBuffer)
|
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, commonBuffer)
|
||||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW)
|
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW)
|
||||||
}
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
case oom: OutOfMemoryError =>
|
||||||
|
HologramRendererFallback.text = "Not enough memory"
|
||||||
|
failed = true
|
||||||
|
false
|
||||||
|
})
|
||||||
|
|
||||||
private def validate(glBuffer: Int) {
|
private def validate(glBuffer: Int) {
|
||||||
// Refresh indexes when the hologram's data changed.
|
// Refresh indexes when the hologram's data changed.
|
||||||
|
@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity
|
|||||||
import org.lwjgl.opengl.GL11
|
import org.lwjgl.opengl.GL11
|
||||||
|
|
||||||
object HologramRendererFallback extends TileEntitySpecialRenderer {
|
object HologramRendererFallback extends TileEntitySpecialRenderer {
|
||||||
val text = "Requires OpenGL 1.5"
|
var text = "Requires OpenGL 1.5"
|
||||||
|
|
||||||
override def renderTileEntityAt(te: TileEntity, x: Double, y: Double, z: Double, f: Float) {
|
override def renderTileEntityAt(te: TileEntity, x: Double, y: Double, z: Double, f: Float) {
|
||||||
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
|
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user