mirror of
https://git.citron-emu.org/citron/emulator
synced 2025-12-19 18:53:32 +00:00
fix(android): Fix aspect ratio crash for non-16:9 settings
- Add missing Force 32:9 option and fix Stretch mapping - Add safety checks to prevent division by zero in FixedRatioSurfaceView - Update handlers to support all 6 AspectRatio enum values Fixes crashes when selecting any aspect ratio other than Force 16:9. Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
@@ -314,6 +314,7 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
|
|||||||
2 -> Rational(21, 9)
|
2 -> Rational(21, 9)
|
||||||
3 -> Rational(16, 10)
|
3 -> Rational(16, 10)
|
||||||
4 -> Rational(32, 9)
|
4 -> Rational(32, 9)
|
||||||
|
5 -> null // Stretch to window
|
||||||
else -> null // Best fit
|
else -> null // Best fit
|
||||||
}
|
}
|
||||||
return this.apply { aspectRatio?.let { setAspectRatio(it) } }
|
return this.apply { aspectRatio?.let { setAspectRatio(it) } }
|
||||||
|
|||||||
@@ -668,6 +668,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||||||
2 -> Rational(21, 9)
|
2 -> Rational(21, 9)
|
||||||
3 -> Rational(16, 10)
|
3 -> Rational(16, 10)
|
||||||
4 -> Rational(32, 9)
|
4 -> Rational(32, 9)
|
||||||
|
5 -> null // Stretch to window
|
||||||
else -> null // Best fit
|
else -> null // Best fit
|
||||||
}
|
}
|
||||||
when (verticalAlignment) {
|
when (verticalAlignment) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||||
|
// SPDX-FileCopyrightText: 2025 citron Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
package org.citron.citron_emu.views
|
package org.citron.citron_emu.views
|
||||||
@@ -27,7 +28,15 @@ class FixedRatioSurfaceView @JvmOverloads constructor(
|
|||||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||||
val displayWidth: Float = MeasureSpec.getSize(widthMeasureSpec).toFloat()
|
val displayWidth: Float = MeasureSpec.getSize(widthMeasureSpec).toFloat()
|
||||||
val displayHeight: Float = MeasureSpec.getSize(heightMeasureSpec).toFloat()
|
val displayHeight: Float = MeasureSpec.getSize(heightMeasureSpec).toFloat()
|
||||||
if (aspectRatio != 0f) {
|
|
||||||
|
// Safety check: ensure we have valid dimensions
|
||||||
|
if (displayWidth <= 0f || displayHeight <= 0f || aspectRatio == 0f) {
|
||||||
|
// Fall back to default behavior for stretch or invalid dimensions
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aspectRatio > 0f) {
|
||||||
val displayAspect = displayWidth / displayHeight
|
val displayAspect = displayWidth / displayHeight
|
||||||
if (displayAspect < aspectRatio) {
|
if (displayAspect < aspectRatio) {
|
||||||
// Max out width
|
// Max out width
|
||||||
|
|||||||
@@ -142,6 +142,7 @@
|
|||||||
<item>@string/ratio_force_four_three</item>
|
<item>@string/ratio_force_four_three</item>
|
||||||
<item>@string/ratio_force_twenty_one_nine</item>
|
<item>@string/ratio_force_twenty_one_nine</item>
|
||||||
<item>@string/ratio_force_sixteen_ten</item>
|
<item>@string/ratio_force_sixteen_ten</item>
|
||||||
|
<item>@string/ratio_force_thirty_two_nine</item>
|
||||||
<item>@string/ratio_stretch</item>
|
<item>@string/ratio_stretch</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
@@ -151,6 +152,7 @@
|
|||||||
<item>2</item>
|
<item>2</item>
|
||||||
<item>3</item>
|
<item>3</item>
|
||||||
<item>4</item>
|
<item>4</item>
|
||||||
|
<item>5</item>
|
||||||
</integer-array>
|
</integer-array>
|
||||||
|
|
||||||
<string-array name="rendererScalingFilterNames">
|
<string-array name="rendererScalingFilterNames">
|
||||||
|
|||||||
@@ -656,6 +656,7 @@
|
|||||||
<string name="ratio_force_four_three">Force 4:3</string>
|
<string name="ratio_force_four_three">Force 4:3</string>
|
||||||
<string name="ratio_force_twenty_one_nine">Force 21:9</string>
|
<string name="ratio_force_twenty_one_nine">Force 21:9</string>
|
||||||
<string name="ratio_force_sixteen_ten">Force 16:10</string>
|
<string name="ratio_force_sixteen_ten">Force 16:10</string>
|
||||||
|
<string name="ratio_force_thirty_two_nine">Force 32:9</string>
|
||||||
<string name="ratio_stretch">Stretch to window</string>
|
<string name="ratio_stretch">Stretch to window</string>
|
||||||
|
|
||||||
<!-- CPU Backend -->
|
<!-- CPU Backend -->
|
||||||
|
|||||||
Reference in New Issue
Block a user