Skip to content
This repository was archived by the owner on Mar 22, 2026. It is now read-only.

Commit 7829933

Browse files
committed
忽略 VMD 文本解码错误
1 parent df4d473 commit 7829933

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

blazerod/model/model-vmd/VmdLoader.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.nio.charset.CodingErrorAction
2222
import java.nio.file.Path
2323
import java.nio.file.StandardOpenOption
2424

25-
class VmdLoadException(message: String) : Exception(message)
25+
class VmdLoadException(message: String, cause: Throwable? = null) : Exception(message, cause)
2626

2727
private inline fun IntIterable.forEachInt(action: (Int) -> Unit) {
2828
val iterator = intIterator()
@@ -56,8 +56,8 @@ class VmdLoader : ModelFileLoader {
5656

5757
private val SHIFT_JIS = Charset.forName("Shift-JIS")
5858
private val decoder = SHIFT_JIS.newDecoder()
59-
.onMalformedInput(CodingErrorAction.REPORT)
60-
.onUnmappableCharacter(CodingErrorAction.REPORT)
59+
.onMalformedInput(CodingErrorAction.REPLACE)
60+
.onUnmappableCharacter(CodingErrorAction.REPLACE)
6161

6262
private fun loadString(buffer: ByteBuffer, maxLength: Int): String {
6363
val bytes = ByteBuffer.allocate(maxLength)
@@ -67,7 +67,14 @@ class VmdLoader : ModelFileLoader {
6767
.indexOfFirst { bytes.get(it) == 0.toByte() }
6868
.takeIf { it != -1 } ?: maxLength
6969
val stringBytes = bytes.slice(0, nullIndex).order(ByteOrder.LITTLE_ENDIAN)
70-
return decoder.decode(stringBytes).toString()
70+
return try {
71+
decoder.decode(stringBytes).toString()
72+
} catch (ex: Exception) {
73+
val hexBytes = (0 until nullIndex).joinToString("") {
74+
"%02X".format(bytes.get(it))
75+
}
76+
throw VmdLoadException("Failed to decode string for byte $hexBytes", ex)
77+
}
7178
}
7279

7380
private fun loadHeader(buffer: ByteBuffer) {

0 commit comments

Comments
 (0)