fixed no data crashes

This commit is contained in:
Alexey 2025-09-30 14:44:28 +03:00
commit b70b98feb6
4 changed files with 5 additions and 6 deletions

View file

@ -63,6 +63,8 @@ class KhmParser {
} }
fun getHeight(lon: Float, lat: Float, ctx: Context): UShort { fun getHeight(lon: Float, lat: Float, ctx: Context): UShort {
if (!ctx.getFileStreamPath(HEIGHT_FILE).exists())
return 0u.toUShort()
val dis = DataInputStream(ctx.openFileInput(HEIGHT_FILE)) val dis = DataInputStream(ctx.openFileInput(HEIGHT_FILE))
dis.use { dis.use {
val header = readHeader(dis) val header = readHeader(dis)
@ -80,7 +82,7 @@ class KhmParser {
@OptIn(ExperimentalUnsignedTypes::class) @OptIn(ExperimentalUnsignedTypes::class)
fun getHeightsMul(ctx: Context, coords: Array<Pair<Float, Float>>): Pair<UShortArray, Array<Pair<Float, Float>>> { fun getHeightsMul(ctx: Context, coords: Array<Pair<Float, Float>>): Pair<UShortArray, Array<Pair<Float, Float>>> {
if (coords.isEmpty()) return Pair(ushortArrayOf(), coords) if (coords.isEmpty() || !ctx.getFileStreamPath(HEIGHT_FILE).exists()) return Pair(ushortArrayOf(), coords)
val dis = DataInputStream(ctx.openFileInput(HEIGHT_FILE)) val dis = DataInputStream(ctx.openFileInput(HEIGHT_FILE))
dis.use { dis.use {
val header = readHeader(dis) val header = readHeader(dis)

View file

@ -26,11 +26,8 @@ import androidx.compose.ui.text.drawText
import androidx.compose.ui.text.rememberTextMeasurer import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.withStyle import androidx.compose.ui.text.withStyle
import kotlin.math.abs
import kotlin.math.absoluteValue import kotlin.math.absoluteValue
import kotlin.math.floor import kotlin.math.floor
import kotlin.math.max
import kotlin.math.min
import kotlin.math.pow import kotlin.math.pow
import kotlin.math.sqrt import kotlin.math.sqrt

View file

@ -23,6 +23,6 @@ class TileRepository(private val tileDao: TileDao) {
} }
fun getMaxLevel(): Int { fun getMaxLevel(): Int {
return coroutineScope.future(Dispatchers.IO){ tileDao.maxLevel() }.join() ?: 1 return coroutineScope.future(Dispatchers.IO){ tileDao.maxLevel() }.join() ?: 2
} }
} }

View file

@ -19,7 +19,7 @@ class TileViewModel(application: Application): ViewModel() {
val mapOffsetX = mutableFloatStateOf(-646.65625F) val mapOffsetX = mutableFloatStateOf(-646.65625F)
val mapOffsetY = mutableFloatStateOf(-1157.2814F) val mapOffsetY = mutableFloatStateOf(-1157.2814F)
val scale = mutableFloatStateOf(2F) val scale = mutableFloatStateOf(2F)
var maxLevel = mutableIntStateOf(1) var maxLevel = mutableIntStateOf(2)
var halvedOffsetX: Float? = null var halvedOffsetX: Float? = null
var halvedOffsetY: Float? = null var halvedOffsetY: Float? = null