hopefully alleviating a bug involving multithreaded (or mixed thread?) usage

This commit is contained in:
minjaesong
2021-11-26 21:06:05 +09:00
parent c3f9ea47fd
commit 45b464ee13
2 changed files with 383 additions and 359 deletions

View File

@@ -394,6 +394,7 @@ class TerrarumSansBitmap(
var index = 0 var index = 0
while (index <= textBuffer.lastIndex) { while (index <= textBuffer.lastIndex) {
try {
val c = textBuffer[index] val c = textBuffer[index]
val sheetID = getSheetType(c) val sheetID = getSheetType(c)
val (sheetX, sheetY) = val (sheetX, sheetY) =
@@ -468,6 +469,12 @@ class TerrarumSansBitmap(
index++ index++
} }
catch (e: NullPointerException) {
System.err.println("Shit hit the multithreaded fan")
e.printStackTrace()
break
}
}
makeShadow(linotypePixmap) makeShadow(linotypePixmap)
@@ -846,6 +853,7 @@ class TerrarumSansBitmap(
// persisting value. the value is set a few characters before the actual usage // persisting value. the value is set a few characters before the actual usage
var extraWidth = 0 var extraWidth = 0
try {
for (charIndex in 0 until posXbuffer.size - 1) { for (charIndex in 0 until posXbuffer.size - 1) {
if (charIndex > 0) { if (charIndex > 0) {
// nonDiacriticCounter allows multiple diacritics // nonDiacriticCounter allows multiple diacritics
@@ -1006,6 +1014,8 @@ class TerrarumSansBitmap(
else { else {
posXbuffer[0] = 0 posXbuffer[0] = 0
} }
}
catch (e: NullPointerException) {}
return posXbuffer to posYbuffer return posXbuffer to posYbuffer
} }
@@ -1345,10 +1355,16 @@ class TerrarumSansBitmap(
val hashPrime = 1099511628211L val hashPrime = 1099511628211L
var hashAccumulator = hashBasis var hashAccumulator = hashBasis
try {
this.forEach { this.forEach {
hashAccumulator = hashAccumulator xor it.toLong() hashAccumulator = hashAccumulator xor it.toLong()
hashAccumulator *= hashPrime hashAccumulator *= hashPrime
} }
}
catch (e: NullPointerException) {
System.err.println("CodepointSequence is null?!")
e.printStackTrace()
}
return hashAccumulator return hashAccumulator
} }

View File

@@ -278,8 +278,8 @@ class TerrarumTypewriterBitmap(
private val pixmapOffsetY = 10 private val pixmapOffsetY = 10
private val linotypePad = 16 private val linotypePad = 16
private var flagFirstRun = true private var flagFirstRun = true
private var textBuffer = CodepointSequence(256) private @Volatile var textBuffer = CodepointSequence(256)
private lateinit var tempLinotype: Texture private @Volatile lateinit var tempLinotype: Texture
private var nullProp = GlyphProps(15) private var nullProp = GlyphProps(15)
@@ -333,6 +333,7 @@ class TerrarumTypewriterBitmap(
var index = 0 var index = 0
while (index <= textBuffer.lastIndex) { while (index <= textBuffer.lastIndex) {
try {
val c = textBuffer[index] val c = textBuffer[index]
val sheetID = getSheetType(c) val sheetID = getSheetType(c)
val (sheetX, sheetY) = val (sheetX, sheetY) =
@@ -343,12 +344,10 @@ class TerrarumTypewriterBitmap(
if (TerrarumSansBitmap.isColourCode(c)) { if (TerrarumSansBitmap.isColourCode(c)) {
if (c == 0x100000) { if (c == 0x100000) {
renderCol = -1 renderCol = -1
} } else {
else {
renderCol = getColour(c) renderCol = getColour(c)
} }
} } else {
else {
try { try {
val posY = posYbuffer[index].flipY() val posY = posYbuffer[index].flipY()
val posX = posXbuffer[index] val posX = posXbuffer[index]
@@ -358,14 +357,19 @@ class TerrarumTypewriterBitmap(
linotypePixmap.drawPixmap(it, posX + linotypePad, posY + pixmapOffsetY, renderCol) linotypePixmap.drawPixmap(it, posX + linotypePad, posY + pixmapOffsetY, renderCol)
} }
} } catch (noSuchGlyph: ArrayIndexOutOfBoundsException) {
catch (noSuchGlyph: ArrayIndexOutOfBoundsException) {
} }
} }
index++ index++
} }
catch (e: NullPointerException) {
System.err.println("Shit hit the multithreaded fan")
e.printStackTrace()
break
}
}
tempLinotype = Texture(linotypePixmap) tempLinotype = Texture(linotypePixmap)
tempLinotype.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest) tempLinotype.setFilter(Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest)
@@ -417,6 +421,7 @@ class TerrarumTypewriterBitmap(
// persisting value. the value is set a few characters before the actual usage // persisting value. the value is set a few characters before the actual usage
var extraWidth = 0 var extraWidth = 0
try {
for (charIndex in 0 until posXbuffer.size - 1) { for (charIndex in 0 until posXbuffer.size - 1) {
if (charIndex > 0) { if (charIndex > 0) {
// nonDiacriticCounter allows multiple diacritics // nonDiacriticCounter allows multiple diacritics
@@ -555,6 +560,8 @@ class TerrarumTypewriterBitmap(
else { else {
posXbuffer[0] = 0 posXbuffer[0] = 0
} }
}
catch (e: NullPointerException) {}
return posXbuffer to posYbuffer return posXbuffer to posYbuffer
} }
@@ -609,14 +616,15 @@ class TerrarumTypewriterBitmap(
val hashPrime = 1099511628211L val hashPrime = 1099511628211L
var hashAccumulator = hashBasis var hashAccumulator = hashBasis
if (this != null) { try {
this.forEach { this.forEach {
hashAccumulator = hashAccumulator xor it.toLong() hashAccumulator = hashAccumulator xor it.toLong()
hashAccumulator *= hashPrime hashAccumulator *= hashPrime
} }
} }
else { catch (e: NullPointerException) {
System.err.println("CodepointSequence is null?!") System.err.println("CodepointSequence is null?!")
e.printStackTrace()
} }
return hashAccumulator return hashAccumulator