Skip to content

Commit

Permalink
Catch and log exceptions during char size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Feb 11, 2024
1 parent 05687ef commit 899115f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import xyz.xenondevs.nova.data.resources.builder.font.provider.ReferenceProvider
import xyz.xenondevs.nova.data.resources.builder.task.PackTask
import xyz.xenondevs.nova.data.resources.builder.task.PackTaskHolder
import xyz.xenondevs.nova.data.resources.builder.task.font.FontContent
import java.util.logging.Level

class CharSizeCalculator internal constructor(builder: ResourcePackBuilder) : PackTaskHolder {

Expand All @@ -25,8 +26,9 @@ class CharSizeCalculator internal constructor(builder: ResourcePackBuilder) : Pa

val fonts = fontContent.mergedFonts
val references = fonts.values.associateWith { it.mapReferences(fonts.values) }
CollectionUtils.sortDependencies(fonts.values) { references[it]!! }
.forEach { font ->
val sortedFonts = CollectionUtils.sortDependencies(fonts.values) { references[it]!! }
for (font in sortedFonts) {
try {
val id = font.id
val table = CharSizeTable()
for (provider in font.providers.reversed()) {
Expand All @@ -40,7 +42,10 @@ class CharSizeCalculator internal constructor(builder: ResourcePackBuilder) : Pa
}

CharSizes.storeTable(id, table)
} catch (t: Throwable) {
LOGGER.log(Level.SEVERE, "Failed to calculate char sizes for font ${font.id}", t)
}
}

CharSizes.invalidateCache()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class RasterGlyphGrid(

init {
require(raster.size == gridWidth * glyphWidth * gridHeight * glyphHeight) { "Raster size does not match other parameters" }
require(glyphWidth in 0..256 && glyphHeight in 0..256) { "Max glyph size is 256x256" }
require(glyphWidth in 0..256 && glyphHeight in 0..256) { "Max glyph size is 256x256 (got $glyphWidth x $glyphHeight)" }
}

override fun get(x: Int, y: Int): IntArray {
Expand Down Expand Up @@ -163,7 +163,7 @@ class ReferenceGlyphGrid(
)

init {
require(glyphWidth in 0..256 && glyphHeight in 0..256) { "Max glyph size is 256x256 (got $" }
require(glyphWidth in 0..256 && glyphHeight in 0..256) { "Max glyph size is 256x256 (got $glyphWidth x $glyphHeight)" }
}

override var gridWidth = grid.size
Expand Down

0 comments on commit 899115f

Please sign in to comment.