mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -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(). */
|
||||
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) {
|
||||
if (failed) {
|
||||
HologramRendererFallback.renderTileEntityAt(te, x, y, z, f)
|
||||
return
|
||||
}
|
||||
|
||||
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
|
||||
|
||||
hologram = te.asInstanceOf[Hologram]
|
||||
@ -142,12 +153,13 @@ object HologramRenderer extends TileEntitySpecialRenderer with Callable[Int] wit
|
||||
}
|
||||
|
||||
def draw(glBuffer: Int) {
|
||||
initialize()
|
||||
validate(glBuffer)
|
||||
publish(glBuffer)
|
||||
if (initialize()) {
|
||||
validate(glBuffer)
|
||||
publish(glBuffer)
|
||||
}
|
||||
}
|
||||
|
||||
private def initialize() {
|
||||
private def initialize(): Boolean = !failed && (try {
|
||||
// First run only, create structure information.
|
||||
if (commonBuffer == 0) {
|
||||
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.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) {
|
||||
// Refresh indexes when the hologram's data changed.
|
||||
|
@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
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) {
|
||||
RenderState.checkError(getClass.getName + ".renderTileEntityAt: entering (aka: wasntme)")
|
||||
|
Loading…
x
Reference in New Issue
Block a user