Android Question Crashing resume

Spright

Active Member
Been developing a game on B4A using Libgdx Library for over a year now, but suddenly on newer phones, it stopped working.
We worked hard to minimie the problem into a working example to show, just to notice that the problem is also present in the simpler demos given along with the library, so here is one example to show what happens. This is really a disaster as we cannot understand at all why this is happening and how to get it back to work again?

All it says is when you go back to the app "waiting for pause synchronization took too long; assuming deadlock and killing"?

This example will only need two libraries, Libgdx and Libgdx_SpecialFX.

B4X:
' Uses LibGDX library & LibGDX_SpecialFX Library
'
' On newer phones resuming (especially via leftmost button) will make the
' app prone to crash with the message:
' "waiting for pause synchronization took too long; assuming deadlock and killing"
'
' Code works perfectly up to Android Pie, but not API 33.

#Region  Project Attributes
    #ApplicationLabel: Perf_Smileys_Blur
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false
#End Region

Sub Process_Globals
    Type typSmiley(X As Float, Y As Float, dX As Float, dY As Float, Color As lgColor)
    Dim FPSLabelTimer As Timer
End Sub

Sub Globals
    Dim Surface As View, lGdx As LibGDX,  GL As lgGL
    Dim Batch As lgSpriteBatch, Camera As lgOrthographicCamera
    Dim lblFPS As Label, spinNS As Spinner, skBlur As SeekBar
    Dim texSmiley As lgTexture,  lstSmileys As List, Quantity As Int
    Dim DefaultShader, BlurShader As lgShaderProgram
    Dim FX As lgSpecialFX,  FXParam(4) As lgSpecialFX_Param
    Dim FirstBuffer, SecondBuffer As lgFrameBuffer
    Dim BufferWidth, BufferHeight As Int
    Dim BlurTR As lgTextureRegion,  Downsampling As Float = 4
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.Title = "libGDX - Performance"
    Dim Config As lgConfiguration
    Config.useAccelerometer = False
    Config.useCompass = False
    Surface = lGdx.InitializeView2(Config, "LG")
    Activity.AddView(Surface, 0, 0, 100%x, 78%y)
    ' Creates the FPS label
    lblFPS.Initialize("")
    lblFPS.TextSize = 24 : lblFPS.TextColor = Colors.Green : lblFPS.Text = "FPS"
    Activity.AddView(lblFPS, 20dip, 86%y, 100dip, 60dip)
    FPSLabelTimer.Initialize("Timer", 500)
    ' Creates the spinner for the number of smileys
    spinNS.Initialize("spinNS") : spinNS.TextSize = 24 : spinNS.Prompt = "Number of smileys"
    For i = 25 To 1000 Step 25
        spinNS.Add(i)
    Next
    spinNS.SelectedIndex = 1
    Activity.AddView(spinNS, 130dip, 84%y, 150dip, 50dip)
    ' Creates the seekbar for the blur strength
    Dim lblBlur As Label
    lblBlur.Initialize("")
    lblBlur.TextSize = 18
    lblBlur.TextColor = Colors.White
    lblBlur.Text = "Blur strength:"
    Activity.AddView(lblBlur, 310dip, 88%y - 28dip, 100%x - 330dip, 25dip)
    skBlur.Initialize("skBlur")
    skBlur.Max = 100
    skBlur.Value = 100
    Activity.AddView(skBlur, 300dip, 88%y, 100%x - 320dip, 32dip)
End Sub

Sub Activity_Resume
    If lGdx.IsInitialized Then lGdx.Resume
    FPSLabelTimer.Enabled = True
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    FPSLabelTimer.Enabled = False
    If lGdx.IsInitialized Then lGdx.Pause
End Sub

Sub LG_Create
    Batch.Initialize
    texSmiley.Initialize("smiley.png")
    texSmiley.SetFilter(texSmiley.FILTER_Linear, texSmiley.FILTER_Linear)
    Quantity = spinNS.SelectedItem
    ' Compile the shaders
    BlurShader.Pedantic = False
    BlurShader.InitializeWithFiles(lGdx.Files.Internal("shaderprog/vertex.txt"), _
                                   lGdx.Files.Internal("shaderprog/fragment_blur_kawase.txt"))
    If Not(BlurShader.IsCompiled) Then
        Log("Could not compile shader: " & BlurShader.Log)
        Return
    End If
    If BlurShader.Log.Length <> 0 Then
        Log(BlurShader.Log)
    End If
End Sub

Sub LG_Resize(Width As Int, Height As Int)
    Camera.Initialize
    Camera.SetToOrtho(False)
    BufferWidth = Width / Downsampling
    BufferHeight = Height / Downsampling
    If FirstBuffer.IsInitialized Then FirstBuffer.dispose
    FirstBuffer.Initialize(FirstBuffer.FORMAT_RGBA8888, BufferWidth, BufferHeight)
    If SecondBuffer.IsInitialized Then SecondBuffer.dispose
    SecondBuffer.Initialize(SecondBuffer.FORMAT_RGBA8888, BufferWidth, BufferHeight)
    ' Creates the region for the blurred texture
    BlurTR.InitializeWithTexture(SecondBuffer.ColorBufferTexture)
    BlurTR.Flip(True, False)
    ' Creates the blur effect
    Dim Fraction As Float = CalcFraction(skBlur.Value)
    Dim TexelWidth As Float = 1 / (BufferWidth * Fraction)
    Dim TexelHeight As Float = 1 / (BufferHeight * Fraction)
    For i = 0 To FXParam.Length - 1
        FXParam(i).Initialize
        FXParam(i).SetFloatParamArray("PixelSize", Array As Float(TexelWidth, TexelHeight))
    Next
    FXParam(0).SetFloatParam("Iteration", 0)
    FXParam(1).SetFloatParam("Iteration", 1)
    FXParam(2).SetFloatParam("Iteration", 1)
    DefaultShader = Batch.CreateDefaultShader
    FX.ClearAllEffects
    FX.AddEffect(DefaultShader, Null, Null, FirstBuffer, "FX")
    FX.AddEffect(BlurShader, FXParam(0), FirstBuffer, SecondBuffer, "")
    FX.AddEffect(BlurShader, FXParam(1), SecondBuffer, FirstBuffer, "")
    FX.AddEffect(BlurShader, FXParam(2), FirstBuffer, SecondBuffer, "")
End Sub

Sub CreateSmileys
    ' Stops the timer used to display the FPS count
    FPSLabelTimer.Enabled = False

    ' Creates the list of smileys
    If lstSmileys.IsInitialized Then
        lstSmileys.Clear
    Else
        lstSmileys.Initialize
    End If
    Dim MU As lgMathUtils
    For i = 1 To Quantity
        Dim Smiley As typSmiley
        Smiley.Initialize
        Smiley.X = Rnd(64dip * 0.5, Surface.Width - (64dip * 1.5))
        Smiley.Y = Rnd(64dip * 0.5, Surface.Height - (64dip * 1.5))
        Smiley.dX = Rnd(3, 6)
        Smiley.dY = Rnd(3, 6)
        If Rnd(0, 2) = 0 Then Smiley.dX = -Smiley.dX
        If Rnd(0, 2) = 0 Then Smiley.dY = -Smiley.dY
        Smiley.Color.SetRGBA(MU.RandomFloat2(0.2, 1), MU.RandomFloat2(0.2, 1), MU.RandomFloat2(0.2, 1), 1)
        lstSmileys.Add(Smiley)
    Next
    Log("Smileys = " & lstSmileys.Size)
    Quantity = 0
    FPSLabelTimer.Enabled = True
End Sub

Sub LG_Render
    If Quantity > 0 Then CreateSmileys
    GL.glClear(GL.GL10_COLOR_BUFFER_BIT) ' Clear screen
    Camera.Update
    Batch.ProjectionMatrix = Camera.Combined
    Try
        LG_Update(lGdx.Graphics.DeltaTime * 20)
        FX.Apply(Batch)
        ' Renders the smileys
        Batch.Shader = DefaultShader
        Batch.Begin
            Batch.DrawRegion2(BlurTR, 0, 0, lGdx.Graphics.Width, lGdx.Graphics.Height)
            For i = 0 To lstSmileys.Size / 2 - 1
                LG_Draw(i, 1)
            Next
        Batch.End
    Catch
        Log(LastException.Message)
    End Try
End Sub

Sub LG_Update(DeltaTime As Float)
    For i = 0 To lstSmileys.Size - 1
        Dim Smiley As typSmiley = lstSmileys.Get(i)
        Smiley.X = Smiley.X + (Smiley.dX * DeltaTime)
        Smiley.Y = Smiley.Y + (Smiley.dY * DeltaTime)
        If Smiley.X <= 0 Then
            Smiley.dX = Abs(Smiley.dX)
        Else If Smiley.X >= Surface.Width - 64dip Then
            Smiley.dX = -Abs(Smiley.dX)
        End If
        If Smiley.Y <= 0 Then
            Smiley.dY = Abs(Smiley.dY)
        Else If Smiley.Y >= Surface.Height - 64dip Then
            Smiley.dY = -Abs(Smiley.dY)
        End If
    Next
End Sub

Sub LG_Draw(Index As Int, Scale As Float)
    Dim Smiley As typSmiley = lstSmileys.Get(Index)
    Batch.Color = Smiley.Color
    Batch.DrawTex2(texSmiley, Smiley.X/Scale, Smiley.Y/Scale, 64dip/Scale, 64dip/Scale)
End Sub

Sub FX_Draw
    GL.glClearColor(0, 0, 0.4, 1)
    GL.glClear(GL.GL10_COLOR_BUFFER_BIT)
    For i = lstSmileys.Size / 2 To lstSmileys.Size - 1
        LG_Draw(i, Downsampling)
    Next
    Batch.SetColorRGBA(1, 1, 1, 1)
End Sub

Sub LG_Resume
End Sub

Sub LG_Pause
End Sub

Sub spinNS_ItemClick(Position As Int, Value As Object)
    Quantity = Value
End Sub

Sub CalcFraction(Value As Int) As Float
    Dim Strength As Int = skBlur.Max - Value
    Strength = Strength * (Strength / skBlur.Max)
    Return Strength / (20 / (Downsampling - 1)) + 1
End Sub

Sub skBlur_ValueChanged (Value As Int, UserChanged As Boolean)
    If Not(UserChanged) Then Return
    Dim Fraction As Float = CalcFraction(Value)
    Dim TexelWidth As Float = 1 / (BufferWidth * Fraction)
    Dim TexelHeight As Float = 1 / (BufferHeight * Fraction)
    For i = 0 To FXParam.Length - 1
        FXParam(i).SetFloatParamArray("PixelSize", Array As Float(TexelWidth, TexelHeight))
    Next
End Sub

Sub Timer_Tick
    lblFPS.Text = "FPS:" & lGdx.Graphics.FramesPerSecond
End Sub

Sub LG_Dispose
    texSmiley.dispose : Batch.dispose : DefaultShader.dispose
    BlurShader.dispose : FirstBuffer.dispose : SecondBuffer.dispose : FX.dispose
End Sub
 

Attachments

  • Shadertest.zip
    343.1 KB · Views: 24

MicroDrie

Well-Known Member
Licensed User
With the Libgdx version 1.14 and Libgdx_SpecialFX version 1.00 the program crashes in the Sub LG_Create with the Batch.Initialize command on line 82 on my Galaxy A13 with Android version 13.
Looking at the dates of the Posts, perhaps it is time for an update of the library?
 
Upvote 0

Spright

Active Member
With the Libgdx version 1.14 and Libgdx_SpecialFX version 1.00 the program crashes in the Sub LG_Create with the Batch.Initialize command on line 82 on my Galaxy A13 with Android version 13.
Looking at the dates of the Posts, perhaps it is time for an update of the library?
Thanks for the input. I've never encountered that, though I use a similar range of Samsung phones, so this information is valuable.
Evidently, there might be other issues with this library.

I want to clarify that the problem I mentioned earlier is only visible when you use the recent button in the navbar to exit the app. If you use the back button or home button to exit, you can use the recent button to get back in without any issues whatsoever. They all still work.

To simplify it, everything still works except when you use the recent button to try to get out of the app. That is when it freezes and eventually shows the message 'Waiting for pause synchronization took too long; assuming deadlock and killing".

 
Upvote 0
Top