mirror of
https://github.com/yairm210/Unciv.git
synced 2025-01-19 16:57:38 +07:00
Fix memory leak from repeatedly resetting the font (#9326)
* Fix memory leak from repeatedly resetting the font * Reduce ruleset recompilation by MainMenuScreen background changes
This commit is contained in:
parent
940fa9a551
commit
100f4ede64
@ -204,6 +204,10 @@ object Fonts {
|
||||
fun resetFont() {
|
||||
val settings = GUI.getSettings()
|
||||
fontImplementation.setFontFamily(settings.fontFamilyData, settings.getFontSize())
|
||||
if (::font.isInitialized) {
|
||||
(font.data as? NativeBitmapFontData)?.dispose() // See #9325
|
||||
// Don't font.dispose() even it it seems obvious -> leaves only black rectangles
|
||||
}
|
||||
font = fontImplementation.getBitmapFont()
|
||||
font.data.markupEnabled = true
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ object ImageGetter {
|
||||
TileSetCache.assembleTileSetConfigs(ruleset.mods)
|
||||
SkinCache.assembleSkinConfigs(ruleset.mods)
|
||||
|
||||
Fonts.resetFont()
|
||||
BaseScreen.setSkin()
|
||||
Fonts.addRulesetImages(ruleset)
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,8 @@ import kotlin.math.min
|
||||
class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
||||
private val backgroundStack = Stack()
|
||||
private val singleColumn = isCrampedPortrait()
|
||||
|
||||
private val backgroundMapRuleset: Ruleset
|
||||
private var easterEggRuleset: Ruleset? = null // Cache it so the next 'egg' can be found in Civilopedia
|
||||
|
||||
private var backgroundMapGenerationJob: Job? = null
|
||||
@ -68,7 +70,7 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
||||
companion object {
|
||||
const val mapFadeTime = 1.3f
|
||||
const val mapFirstFadeTime = 0.3f
|
||||
const val mapReplaceDelay = 15f
|
||||
const val mapReplaceDelay = 20f
|
||||
}
|
||||
|
||||
/** Create one **Main Menu Button** including onClick/key binding
|
||||
@ -117,7 +119,15 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
||||
|
||||
// If we were in a mod, some of the resource images for the background map we're creating
|
||||
// will not exist unless we reset the ruleset and images
|
||||
ImageGetter.ruleset = RulesetCache.getVanillaRuleset()
|
||||
val baseRuleset = RulesetCache.getVanillaRuleset()
|
||||
ImageGetter.ruleset = baseRuleset
|
||||
|
||||
if (game.settings.enableEasterEggs) {
|
||||
val easterEggMod = EasterEggRulesets.getTodayEasterEggRuleset()
|
||||
if (easterEggMod != null)
|
||||
easterEggRuleset = RulesetCache.getComplexRuleset(baseRuleset, listOf(easterEggMod))
|
||||
}
|
||||
backgroundMapRuleset = easterEggRuleset ?: baseRuleset
|
||||
|
||||
// This is an extreme safeguard - should an invalid settings.tileSet ever make it past the
|
||||
// guard in UncivGame.create, simply omit the background so the user can at least get to options
|
||||
@ -209,13 +219,7 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
||||
scale = min(scale, 20f)
|
||||
}
|
||||
|
||||
val baseRuleset = RulesetCache.getVanillaRuleset()
|
||||
easterEggRuleset = EasterEggRulesets.getTodayEasterEggRuleset()?.let {
|
||||
RulesetCache.getComplexRuleset(baseRuleset, listOf(it))
|
||||
}
|
||||
val mapRuleset = if (game.settings.enableEasterEggs) easterEggRuleset ?: baseRuleset else baseRuleset
|
||||
|
||||
val newMap = MapGenerator(mapRuleset, this)
|
||||
val newMap = MapGenerator(backgroundMapRuleset, this)
|
||||
.generateMap(MapParameters().apply {
|
||||
shape = MapShape.rectangular
|
||||
mapSize = MapSizeNew(MapSize.Small)
|
||||
@ -226,7 +230,7 @@ class MainMenuScreen: BaseScreen(), RecreateOnResize {
|
||||
})
|
||||
|
||||
launchOnGLThread { // for GL context
|
||||
ImageGetter.setNewRuleset(mapRuleset)
|
||||
ImageGetter.setNewRuleset(backgroundMapRuleset)
|
||||
val mapHolder = EditorMapHolder(
|
||||
this@MainMenuScreen,
|
||||
newMap
|
||||
|
Loading…
Reference in New Issue
Block a user