I have a piece of code where reading a local integer causes my DBP app to crash. There is no obvious logic to the problem. I've pasted in the function at the end in whole (with the important bits marked with <== - it's hard going!), but the crux of it is around the variable
myScore. Originally I just used
totalScore, but I moved it to the former in case I had some bizarre corruption; it hasn't helped. There's a few quirks to the code that are the result of pinpointing the problem, such as printing out the same message multiple times to a log file.
In brief:
* totalScore is calculated.
* It is successfully displayed as a bitmap font.
* It is successfully printed to a log file and console. (IanM's LOG and CONSOLE commands)
* I move the value to another local variable, myScore (to debug)
* I do a few things in between to allow keyboard input of the player name
<== THIS IS WHAT TRIPS IT, MORE LATER
* I print the value to the log file and console, this is where it crashes (usually but not always).
* If I remove the print to log file and console (or it gets past the log), it crashes at the next use of myScore, at the ENDFUNCTION command.
the Score is never used or updated in the keyboard input code. The addition of this code trips a totally unrelated variable. If I remove the call to the keyboard code, it works again.
I haven't included the keyboard code as it expands out into a few thousand lines of my standard routines. Basically, it creates a set of array elements (I have proven this is not the cause) and then uses these to create 39 images and put them on-screen on plains. Afterwards, they get deleted and the program continues and subsequently crashes.
Thanks in advance for any insight you can give. I think I've hit a problem with the inner workings of DBP given that cause and effect are unrelated. I'm expecting an "Yes, I hit that" response, hopefully with a workaround.
function gameScore()
` Add up the scores
local totalScore as integer
`*** Collect Ball Time and Colours for balls still in play
for n = 1 to g.numBalls
if arrBall(n).state > cBALLONRAMP
gScore.ballTime = gScore.balltime + (hiTimer() - arrBall(n).time)
inc arrGameBalls(arrBall(n).maxLevel),1
endif
Next n
` *** Collector bonus is Won - Lost
if gScore.ballsWon > gScore.ballsLost
collector = int(gScore.multCollect * (gScore.ballsWon - gScore.ballsLost))
else
collector = 0
endif
` *** Juggler bonus is total time for all balls in play
juggler = int((gScore.balltime / 1000.0) * gScore.multJuggle)
` *** Colour bonus for all colours achieved
for n = 2 to 5
colour = colour + int((gScore.multColour * n) * arrGameBalls(n))
next n
` *** Grand Total
totalScore = gScore.fullScore + juggler + collector + colour <== The value that causes crash
debugPrint("Total Score = " + str$(totalScore)) <== Prints and Console OK
gScore.ScoreBank = fontAddPermaPhraseBank(g.gameFont, 6)
fontAddPermaPhrase(gScore.scoreBank,1, "In-Game Score : " + str$(gScore.fullScore))
fontAddPermaPhrase(gScore.scoreBank,2, "Jugglers Bonus : " + str$(juggler))
fontAddPermaPhrase(gScore.scoreBank,3, "Collectors Bonus : " + str$(collector))
fontAddPermaPhrase(gScore.scoreBank,4, "Colour Bonus : " + str$(colour))
fontAddPermaPhrase(gScore.scoreBank,5, " ")
fontAddPermaPhrase(gScore.scoreBank,6, "Total Score : " + str$(totalScore)) <== Bitmap Font Displays OK
` Set the effects for the PermaPhrase Bank. We will use the functions that
` allow simple display of all the permaphrases
fontSetPermaPhraseEffect(cEFFECT_MENU_IN,cEFFECT_MENU_OUT,100, 0)
fontDisplayPermaPhraseBank(gScore.scoreBank,1)
do
if mouseclick() or inkey$() <> ""
exit
endif
update physics
gfUpdateBefore()
sync
gfUpdateAfter()
loop
remstart
fontDisplayPermaPhraseBank(gScore.scoreBank,1)
iTime = Hitimer()
while iTime > Hitimer() - 1100
gfUpdateBefore()
sync
if inkey$() <> "" then exit
endwhile
remend
fontDisplayPermaPhraseBank(gScore.scoreBank,0)
iTime = Hitimer()
while iTime > Hitimer() - 1500
gfUpdateBefore()
sync
`if inkey$() <> "" then exit
endwhile
fontDeletePermaPhraseBank(gScore.scoreBank)
myScore = totalScore <== Save to myScore to aid debugging
debugPrint("My Score = " + str$(myScore)) <== Log and Console OK
initHiScores()
` If Score is on high score table, process
for n = 1 to 10
if totalScore > arrHiScore(n).score
` *** Get name of player
debugPrint("Creating Keyboard")
fontCreateKeyboard(cFONT_KEYBOARD_STANDARD, g.GameFont, cHUD_MARKER_MIDDLE_CENTRE_V)
name$ = fontShowKeyboard(10) <== THIS ONE KILLS IT. Creates and Displays Plains
` Update the high score table
for m = 10 to (n+1) step -1
arrHiScore(m).name = arrHiScore(m -1).name
arrHiScore(m).score = arrHiScore(m -1).score
next m
arrHiScore(n).name = "Temporary"
arrHiScore(n).score = totalScore
writeHiScores()
fontDeleteKeyboard()
exit
endif
next n
debugPrint("End of Score Function")
debugPrint("End of Score Function")
debugPrint(str$(myScore)) <=== CRASH POINT (MOST OF THE TIME)
debugPrint("End of Score Function")
endfunction myScore <== CRASH POINT (THE REST OF THE TIME)
