EventCounter = 0
Do While Not(Done)
' (code that does stuff until stuff is done, then Done = True)
If EventCounter Mod 3 = 0 Then
If Debug Then Log("DoEvents")
DoEvents
EndIf
EventCounter = EventCounter + 1
Loop
If something= something then
' Do a bunch of stuff
else
If Debug then Log("such-and-such")
DoEvents
end if
Change the option in the dropdown, then set a breakpoint on the line you want by clicking in the left hand gutter. You should see a red circle.
View attachment 26416
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
AddPermission(android.permission.GET_TASKS)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.RECORD_AUDIO)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
Use the controls at the top of the debug window, press the play button to continue, the second button to step to the next line or the stop button to exit the session.
View attachment 26417
I get mad reading the complexity of your code. Are you sure you can not do otherwise?
View attachment 26403
Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event
Dim Answ As Int
Dim Volume As Int
Dim Done As Boolean = False
Dim HELPPANEL_NeedsStackBackup As Boolean
Dim TUTORPANEL_NeedsStackBackup As Boolean
DoEntry("Activity_KeyPress()")
If KeyCode = KeyCodes.KEYCODE_VOLUME_UP AND Not(AUDIO_IncreaseBeingUsed) AND pnlLock.Visible = False Then
DEBUG1("Activity_KeyPress() - Increasing Volume")
Volume = LIB_Phone.GetVolume(1)
LIB_Phone.SetVolume(1,Volume+1,SHOW_VOLUME_CONTROL)
AUDIO_IncreaseBeingUsed = True
EnableTIMER(TIMERNUMBER_IncreaseVolume)
End If
If KeyCode = KeyCodes.KEYCODE_VOLUME_DOWN AND Not(AUDIO_DecreaseBeingUsed) AND pnlLock.Visible = False Then
DEBUG1("Activity_KeyPress() - Decreasing Volume")
Volume = LIB_Phone.GetVolume(1)
LIB_Phone.SetVolume(1,Volume-1,SHOW_VOLUME_CONTROL)
AUDIO_DecreaseBeingUsed = True
EnableTIMER(TIMERNUMBER_DecreaseVolume)
End If
If KeyCode = KeyCodes.KEYCODE_BACK Then
DisableTIMER(TIMERNUMBER_GIF)
SaveSettingsScrollPos("")
SaveHelpScrollPos("")
SaveTutorScrollPos("")
StopAllRecordAndPlay("")
CloseAllQuestions("")
CloseURL("")
DEBUG1("Activity_KeyPress() KEYCODE_BACK - STACK_Pointer = " & STACK_Pointer)
' If there are things on the Stack, back-up one
' Unless it is the HELPPANEL, then do a ScrollPos = 0 if ScrollPos isn't zero
' Otherwise do a regular back-up in the stack
If LastPanel = HELPPANEL OR LastPanel = TUTORPANEL Then
DEBUG1("Activity_KeyPress() KEYCODE_BACK - LastPanel = HELPPANEL")
If wvX.getScrollY(wvHelpOrTutor) <> 0 Then
' It wasn't at the top, so set it to the top and don't back-up one level in the stack
If LastPanel = HELPPANEL Then
HELPPANEL_NeedsStackBackup = False
DEBUG1("Activity_KeyPress() KEYCODE_BACK - wvHelpOrTutor.Top <> 0; HELPPANEL_NeedsStackBackup = False")
Else
TUTORPANEL_NeedsStackBackup = False
DEBUG1("Activity_KeyPress() KEYCODE_BACK - wvHelpOrTutor.Top <> 0; TUTORPANEL_NeedsStackBackup = False")
End If
wvE.PageUp(True)
DEBUG1("Activity_KeyPress() KEYCODE_BACK - Set wvHelpOrTutor.Top = 0")
DEBUG1("Activity_KeyPress() - DoEvents #1")
DoEvents
Else
' It was already at the top, so they just want to back up one stack level
If LastPanel = HELPPANEL Then
DEBUG1("Activity_KeyPress() KEYCODE_BACK - wvHelpOrTutor.Top = 0; HELPPANEL_NeedsStackBackup = True")
HELPPANEL_NeedsStackBackup = True
Else
DEBUG1("Activity_KeyPress() KEYCODE_BACK - wvHelpOrTutor.Top = 0; TUTORPANEL_NeedsStackBackup = True")
TUTORPANEL_NeedsStackBackup = True
End If
End If
End If
If (LastPanel <> HELPPANEL AND LastPanel <> TUTORPANEL) OR (LastPanel = HELPPANEL AND HELPPANEL_NeedsStackBackup = True) OR _
(LastPanel = TUTORPANEL AND TUTORPANEL_NeedsStackBackup = True) Then
Done = False
EventCounter = 0
Do While Done = False
' Throw away multiple LastPanels that are all the same
If STACK(STACK_Pointer) = LastPanel Then
STACK_Pointer = STACK_Pointer - 1
DEBUG1("Activity_KeyPress() KEYCODE_BACK - Subtracting 1 from Stack Pointer")
Else
Done = True
End If
If STACK_Pointer = 0 Then Done = True
If EventCounter Mod 3 = 0 Then
DEBUG1("Activity_KeyPress() KEYCODE_BACK - DoEvents")
DoEvents
End If
EventCounter = EventCounter + 1
Loop
End If
If STACK_Pointer <> 0 Then
DEBUG1("Activity_KeyPress() KEYCODE_BACK - STACK_Pointer = " & STACK_Pointer)
' Pull Panel off the Stack and jump to it
Dim OldStackPointer As Int = STACK_Pointer
If (LastPanel <> HELPPANEL AND LastPanel <> TUTORPANEL) OR (LastPanel = HELPPANEL AND HELPPANEL_NeedsStackBackup = True) OR (LastPanel = TUTORPANEL AND TUTORPANEL_NeedsStackBackup = True) Then
STACK_Pointer = STACK_Pointer - 1
DEBUG1("Activity_KeyPress() KEYCODE_BACK - STACK(" & OldStackPointer & ") = " & PANELNAMES(STACK(OldStackPointer)))
FLAG_LastPanelLoaded = LastPanel
CallSubDelayed("", MenuClicks(STACK(OldStackPointer)))
DoEvents
End If
Else If pnlWB.Visible = True Then
If WebViewWB.Visible = True Then
' If WB Question Panel is open, close it
CloseWBQuestion("")
Else
If pnlLock.Visible = False Then
TurnOnDimmedPanel("")
Answ = DialogResponse.CANCEL
EventCounter = 0
Do While Answ = DialogResponse.CANCEL
Answ = Msgbox2("Do you want to quit the program ?", _
"A T T E N T I O N", "Yes", "", "No", Null)
If EventCounter Mod 3 = 0 Then
DEBUG1(" - DoEvents")
DoEvents
End If
EventCounter = EventCounter + 1
Loop
If Answ = DialogResponse.NEGATIVE Then
DEBUG1("KEYCODE_BACK - Dialog Response NO pressed")
TurnOffDimmedPanel("")
Else
DEBUG1("KEYCODE_BACK - Dialog Response YES pressed")
If Not(IsPaused(Overlord)) Then StopService(Overlord)
Activity.Finish
End If
End If
End If
Else
' They aren't on the WorkBook panel, so back up to main panel
' Ensure that they didn't just come from Overlord
' If they did, this aborts Overlord's RestoreActivity
StartUpLesson("")
End If
End If
DoEvents
DoExit("Activity_KeyPress()")
Return True
End Sub
Use the controls at the top of the debug window, press the play button to continue, the second button to step to the next line or the stop button to exit the session.
View attachment 26417
Use the controls at the top of the debug window, press the play button to continue, the second button to step to the next line or the stop button to exit the session.
View attachment 26417
When you have found the error you will have to remove all those "DoEvents" - I hope you have a copy that does not contain them!
In the Log window, try to uncheck the Filter
You can try this tip from Erel: http://www.b4x.com/android/forum/threads/thread-usage.39311/#post-233482
Timeout executing service: ServiceRecord{4379f7e8 u0 b4a.acim/.overlord}
...
Wrote stack traces to '/data/anr/traces.txt'
...
(keeps trying)
...
Reason: Executing service b4a.acim/.overlord
Load: 5.71 / 5.24 / 5.13
CPU usage from 20445ms to 0ms ago with 99% awake:
8.2% 19998/b4a.acim: 6.3% user + 1.9% kernel / faults: 88 minor
CPU usage from 2473ms to 3001ms later with 99% awake:
21% 19998/b4a.acim: 14% user + 7.1% kernel / faults: 1473 minor
Lets pick any random subroutine. I'd bet that without seeing any other subroutine, you can easily figure out what the code is doing:
B4X:Sub Activity_KeyPress(KeyCode As Int) As Boolean 'Return True to consume the event ............ If (LastPanel <> HELPPANEL AND LastPanel <> TUTORPANEL) OR (LastPanel = HELPPANEL AND HELPPANEL_NeedsStackBackup = True) OR _ (LastPanel = TUTORPANEL AND TUTORPANEL_NeedsStackBackup = True) Then Done = False EventCounter = 0 Do While Done = False ' Throw away multiple LastPanels that are all the same If STACK(STACK_Pointer) = LastPanel Then STACK_Pointer = STACK_Pointer - 1 DEBUG1("Activity_KeyPress() KEYCODE_BACK - Subtracting 1 from Stack Pointer") Else Done = True End If If STACK_Pointer = 0 Then Done = True If EventCounter Mod 3 = 0 Then DEBUG1("Activity_KeyPress() KEYCODE_BACK - DoEvents") DoEvents End If EventCounter = EventCounter + 1 Loop End If ............ Do While Answ = DialogResponse.CANCEL Answ = Msgbox2("Do you want to quit the program ?", _ "A T T E N T I O N", "Yes", "", "No", Null) If EventCounter Mod 3 = 0 Then DEBUG1(" - DoEvents") DoEvents End If EventCounter = EventCounter + 1 Loop ............
If STACK_Pointer = 0 Then Done = True
Msgbox2 (Message AsString, Title AsString, Positive AsString, Cancel AsString, Negative AsString, Icon As android.graphics.Bitmap) AsIntShows a modal message box with the specified message and title.
Message - The dialog message.
Title - The dialog title.
Positive - The text to show for the "positive" button. Pass "" if you don't want to show the button.
Cancel - The text to show for the "cancel" button. Pass "" if you don't want to show the button.
Negative - The text to show for the "negative" button. Pass "" if you don't want to show the button.
Icon - A bitmap that will be drawn near the title. Pass Null if you don't want to show an icon.
Returns one of the DialogResponse values.
Exampleim result AsInt
result = Msgbox2("This is the message", "This is the title", "Good", "", "Bad", LoadBitmap(File.DirAssets, "smiley.gif"))If result = DialogResponse.Positive Then ...
I'm just spit-balling here in the hope that it might give you a new direction to go in, I'm only a hobbyist programmer and there's far more experienced people here on the forum. It looks to me like its possible for your code to get stuck in an endless loop if STACK_Pointer is not at the value you expect it to be.I'm always inclined to use "<= 0" in any comparison instruction to ensure that if the value goes negative then I can still continue with the program execution. Maybe the problem isn't in this routine, but if you've done the same in other routines then its something that could be looked at?B4X:If STACK_Pointer = 0 Then Done = True
I've also never seen a MsgBox programmed this way, there is no need for the Do While loop. The MsgBox will halt program execution until the user presses an option or cancels. Below is the example usage given in the docs.
I hope this gives you something more to look at and that you soon find the fault. I know just how frustrating some of these faults can be to track down
Kind regards,
RandomCoder
I'm just spit-balling here in the hope that it might give you a new direction to go in, I'm only a hobbyist programmer and there's far more experienced people here on the forum. It looks to me like its possible for your code to get stuck in an endless loop if STACK_Pointer is not at the value you expect it to be.I'm always inclined to use "<= 0" in any comparison instruction to ensure that if the value goes negative then I can still continue with the program execution. Maybe the problem isn't in this routine, but if you've done the same in other routines then its something that could be looked at?B4X:If STACK_Pointer = 0 Then Done = True
I've also never seen a MsgBox programmed this way, there is no need for the Do While loop. The MsgBox will halt program execution until the user presses an option or cancels. Below is the example usage given in the docs.
I hope this gives you something more to look at and that you soon find the fault. I know just how frustrating some of these faults can be to track down
Kind regards,
RandomCoder
I'm just spit-balling here in the hope that it might give you a new direction to go in, I'm only a hobbyist programmer and there's far more experienced people here on the forum. It looks to me like its possible for your code to get stuck in an endless loop if STACK_Pointer is not at the value you expect it to be.I'm always inclined to use "<= 0" in any comparison instruction to ensure that if the value goes negative then I can still continue with the program execution. Maybe the problem isn't in this routine, but if you've done the same in other routines then its something that could be looked at?B4X:If STACK_Pointer = 0 Then Done = True
I've also never seen a MsgBox programmed this way, there is no need for the Do While loop. The MsgBox will halt program execution until the user presses an option or cancels. Below is the example usage given in the docs.
I hope this gives you something more to look at and that you soon find the fault. I know just how frustrating some of these faults can be to track down
Kind regards,
RandomCoder
I'm just spit-balling here in the hope that it might give you a new direction to go in, I'm only a hobbyist programmer and there's far more experienced people here on the forum. It looks to me like its possible for your code to get stuck in an endless loop if STACK_Pointer is not at the value you expect it to be.I'm always inclined to use "<= 0" in any comparison instruction to ensure that if the value goes negative then I can still continue with the program execution. Maybe the problem isn't in this routine, but if you've done the same in other routines then its something that could be looked at?B4X:If STACK_Pointer = 0 Then Done = True
I've also never seen a MsgBox programmed this way, there is no need for the Do While loop. The MsgBox will halt program execution until the user presses an option or cancels. Below is the example usage given in the docs.
I hope this gives you something more to look at and that you soon find the fault. I know just how frustrating some of these faults can be to track down
Kind regards,
RandomCoder
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?