Skip to content

Commit

Permalink
fix: crash upon displaying many saved scenes
Browse files Browse the repository at this point in the history
This commit fixes a critical issue that once the user saved around 20 scenes, it would always crash to show the saved scenes, till the app's data is reseted.
  • Loading branch information
ThePedroo committed Apr 23, 2024
1 parent 87132af commit 065c18e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 5 additions & 3 deletions android/app/src/main/java/com/perforvnm/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ class MainActivity : Activity() {
val saves = JSONArray(text)

var leftDp = 100
var topDp = 50
var topDpIndex = 0

for (i in 0 until saves.length()) {
val buttonData = saves.getJSONObject(i)
Expand All @@ -1190,7 +1190,9 @@ class MainActivity : Activity() {
)

val leftDpLoad = resources.getDimensionPixelSize(resources.getIdentifier("_${leftDp}sdp", "dimen", getPackageName()))
val topDpLoad = resources.getDimensionPixelSize(resources.getIdentifier("_${topDp}sdp", "dimen", getPackageName()))

var topDpLoad = resources.getDimensionPixelSize(com.intuit.sdp.R.dimen._50sdp)
if (topDpIndex != 0) topDpLoad += sdp100 * topDpIndex

layoutParamsSavesBackground.gravity = Gravity.TOP or Gravity.START
layoutParamsSavesBackground.setMargins(leftDpLoad, topDpLoad, 0, 0)
Expand Down Expand Up @@ -1309,7 +1311,7 @@ class MainActivity : Activity() {

if (i != 0 && (i + 1).mod(4) == 0) {
leftDp = 100
topDp += 100
topDpIndex++
} else {
leftDp += 133
}
Expand Down
12 changes: 8 additions & 4 deletions platforms/android/menu.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* TODO: Allow to remove footer and add buttons manually */
/* TODO (Critical): Fix saves, if saves topDp > 620 then it will crash the app */

import helper from '../main/helper.js'

Expand Down Expand Up @@ -1192,6 +1191,9 @@ export function _AddMenu() {
const sdp100Saves = _GetMultiResources(androidMenu, androidMenu.pages.savesFor, { type: 'sdp', dp: '100' })
androidMenu.pages.savesFor = _AddResource(androidMenu.pages.savesFor, { type: 'sdp', dp: '100', spaces: 6, newLines: sdp70Saves.definition ? '\n' : '\n\n' })

const sdp50Saves = _GetMultiResources(androidMenu, androidMenu.pages.savesFor, { type: 'sdp', dp: '50' })
androidMenu.pages.savesFor = _AddResource(androidMenu.pages.savesFor, { type: 'sdp', dp: '50', spaces: 6 })

let scenesInfoCalculations = ''
if (visualNovel.optimizations.preCalculateScenesInfo) {
scenesInfoCalculations = helper.codePrepare(`\n
Expand Down Expand Up @@ -1405,7 +1407,7 @@ __PERFORVNM_SAVES_SWITCH__
val saves = JSONArray(text)
var leftDp = 100
var topDp = 50
var topDpIndex = 0
for (i in 0 until saves.length()) {
val buttonData = saves.getJSONObject(i)
Expand All @@ -1427,7 +1429,9 @@ __PERFORVNM_SAVES_SWITCH__
)
val leftDpLoad = resources.getDimensionPixelSize(resources.getIdentifier("_\${leftDp}sdp", "dimen", getPackageName()))
val topDpLoad = resources.getDimensionPixelSize(resources.getIdentifier("_\${topDp}sdp", "dimen", getPackageName()))
${sdp50Saves.definition}var topDpLoad = ${sdp50Saves.variable}
if (topDpIndex != 0) topDpLoad += ${sdp100Saves.variable} * topDpIndex
layoutParamsSavesBackground.gravity = Gravity.TOP or Gravity.START
layoutParamsSavesBackground.setMargins(leftDpLoad, topDpLoad, 0, 0)
Expand Down Expand Up @@ -1456,7 +1460,7 @@ __PERFORVNM_SAVES_SWITCH__
if (i != 0 && (i + 1).mod(4) == 0) {
leftDp = 100
topDp += 100
topDpIndex++
} else {
leftDp += 133
}
Expand Down

0 comments on commit 065c18e

Please sign in to comment.