Hardware Acceleration problem

sterlingy

Active Member
Licensed User
Longtime User
I'm running my app on a Galaxy S3. Several Apps run fine with Hardware Acceleration enabled, but one app always tells me that Hardware Acceleration is not supported. This message comes up regardless as to whether the attribute is enabled or not in the Manifest.

I should point out that I did have to add the Attribute to the Manifest, whereas, the other apps already had the attribute in the Manifest and enabled from the beginning.

-Sterling
 

sterlingy

Active Member
Licensed User
Longtime User
Okay, I figured out that a new Manifest file was being created, so I added the hardware accelerator attribute to the real manifest using WordPad. Now I don't get the notification, but my app runs REALLY slow.

Thoughts?

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
I started by using the Manifest editor, and I added the line, just as you showed in the example you referenced. Nothing changed.

What I noticed was that B4A created a new file called AndroidManifest-Example.xml.

After that, I tried changing the Manifest file outside of B4A. This did get rid of the warning message that Hardware Acceleration was not supported, but then things really slowed down.

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
This means that either you have checked: Project - Do not overwrite manifest file, or that the manifest file is readonly.

Well blow me down! A problem has been resolved. You were correct in that I had checked "Do not overwrite Manifest File." I didn't even see that option.

Unfortunately, the app still runs slower with Hardware Acceleration enabled.

Something else I noticed, when I opened the Manifest file, it was using SDK version "4." I changed this to 11. Maybe there is a better place to make that change. I'm not sure if this is the cause for the slowdown.

Thanks!!

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
I'm narrowing down the problem. I think I may have introduced a conflict, which may be the cause for the slowdown.

In my app, which is loosely based on the Asteroids example, I have two different sprites, Leroy and Dog. Leroy is based on the Asteroid Ship sprite and Dog is based on the Asteriods. They are both set up in the same way, from the GameManager:

B4X:
Public Sub AddLeroy
   Dim animator As SpriteAnimator
   Dim rects(6) As Rect
   Dim bitmaps(6) As Bitmap
   Dim row As Int
   row = 0
   'The Leroy sprite sheet includes 1 row of sprites.
   For i = 0 To 5
      rects(i) = leroyBitmaps(i, row).SrcRect
      bitmaps(i) = leroyBitmaps(i, row).Bitmap
   Next
   
   animator.Initialize
   Dim bd As BitmapData
   animator.SetFrames(bd, rects, bitmaps) 'sets the frames that will be animated
   animator.AnimationInterval = 10

   MyLeroy.Initialize(bd, animator, Me, 50%x, 65%y, 250)

   gv.BitmapsData.Add(bd) 'add Leroy to the GameView (so it will be redrawn every time).

End Sub

Public Sub AddDog (x As Int, y As Int, size As Int)
   Dim animator As SpriteAnimator
   Dim rects(6) As Rect
   Dim bitmaps(6) As Bitmap
   Dim row As Int
   row = Rnd(0, 2)
   'The Dogs sprite sheet includes 4 rows of sprites.
   'One of the rows is randomly selected.
   For i = 0 To 5
      rects(i) = DogsBitmaps(i, row).SrcRect
      bitmaps(i) = DogsBitmaps(i, row).Bitmap
   Next
   
   animator.Initialize
   Dim bd As BitmapData
   animator.SetFrames(bd, rects, bitmaps) 'sets the frames that will be animated
   animator.AnimationInterval = 10
   Dim doggie As Dog
   doggie.Initialize(bd, animator, Me, x, y, 125)
   Dogs.Add(doggie) 'add the Dog to the Dogs list.
   gv.BitmapsData.Add(bd) 'add the Dog to the GameView (so it will be redrawn every time).
End Sub

Leroy has it's own class and as soon as it references Leroy from the GameManger, things slow to a snail's pace.

B4X:
Public Sub Initialize (vBD As BitmapData, vAnimator As SpriteAnimator, vGame As GameManager, _ 
      x As Int, y As Int, size As Int)
      
      
'   animator.Initialize
'   leroyBd = vBD
'   leroyStillBmp = LoadBitmap(File.DirAssets, "leroy_still.png")
'   
'   animator.width = 30 * GameUtils.scale 'set the sprite width and height
'   animator.height = 45 * GameUtils.scale
'   Dim x, y As Int
'   x = 50%x - animator.width / 2 'start in the middle of the screen
'   y = 68%y - animator.height / 2
'   leroyBd.DestRect.Initialize(x, y , x + animator.width, y + animator.height)   
      
   
   animator = vAnimator
   animator.width = size
   animator.height = animator.width
   leroyBd = vBD
   leroyBd.DestRect.Initialize(x, y, x + animator.width, y + animator.height)

   game = vGame
   

End Sub
.
.
.
.
.
.
.
Public Sub Tick
   ticks = ticks + 1
   If state = STATE_NORMAL Then
      'check the left joystick and change the rotation and speed
      Dim dx, dy, vx, vy As Int
      Dim tmpRect As Rect
      tmpRect = game.leroyBitmaps(0,0).SrcRect

      Select game.pad.GetLeftValue
         Case game.pad.LEFT
            leroyBd.Rotate = leroyBd.Rotate - 2
            vx = vx - 4
         Case game.pad.RIGHT
            leroyBd.Rotate = leroyBd.Rotate + 2
            vx = vx + 4
         Case game.pad.UP      
            vy = vy - 4
         Case game.pad.DOWN
            vy = vy + 4
         Case game.pad.NONE
'
               speed = 0
'   animator.SetFrames(leroyBd, Array As Rect(leroyRect), Array As Bitmap(leroyStillBmp))
   animator.SetFrames(leroyBd, Array As Rect(tmpRect), Array As Bitmap(leroyBd.Bitmap))
      End Select
.
.
.
.

Alternately, If I switch the code around, uncomment the beginning of the initialize routine and comment the 5 lines before "game = vGame" and switch between the last two lines in the Tick routine code, things run smoothly.

So, a reference to the GameManager's "leroyBd.Bitmap" (parsed up by LoadSpritesFromSheet) is slower than a direct reference to the bitmap that was loaded in the Leroy Class.

Thoughts?

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Can you upload your complete project (File - Export as zip)?

Here it is, without images. If it would help, I can make some small dummy images that I could probably upload within the limits set for attachments to messages.

-Sterling
 

Attachments

  • GameApp_HardwareAccel_Prob.zip
    14.6 KB · Views: 265
  • dummy images.zip
    300.8 KB · Views: 266
Last edited:
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Erel,

The code is a bit of a mess at the moment. the 250 was put there, just to see how that size sprite looked. I'll clean things up as I go along.

I made dummy images for everything, and I ran the App, and everything worked!! I started swapping in the original images, and at some point everything slowed down. This leaves me to believe that it is a memory problem.

I added the dummy images to my previous post:

http://www.b4x.com/forum/basic4andr...hardware-acceleration-problem.html#post160579

Everything will work, but start replacing images with large memory hogs, and you'll see what happens.

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
I was loading large images, but I have since scaled everything down. My concern is how to deal with some of these new tablets that have resolutions over 2K in one direction, so if you want to move around a large map, you'' have to scale everything up in the app and it might not look very nice.

Also, is it simple the size of the images, or can the quantity of bitmaps also result in problems?

In other words, let's say I had 4 images that were large and slowed the system down, so I scale them down to 25%, now I add more sprites to my program. If I added 12 more bitmaps, giving me 16 in total, I would effectively be using the same amount of memory as the 4 larger images. Would I get the same negative result?

-Sterling
 
Upvote 0

sterlingy

Active Member
Licensed User
Longtime User
Is there a way to determine how much memory is available for bitmaps? I know this is device specific.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
To know the free memory on a device:
Prior Honeycomb:
B4X:
Sub GetFreeMem As Float
   Dim r As Reflector
   Dim MM, TM, FM, Total As Int
   r.Target = r.RunStaticMethod("java.lang.Runtime", "getRuntime", Null, Null)
   MM = r.RunMethod("maxMemory")
   FM = r.RunMethod("freeMemory")
   TM = r.RunMethod("totalMemory")
   Total = MM + FM - TM - r.RunStaticMethod("android.os.Debug", "getNativeHeapAllocatedSize", Null, Null)
   Return Total / 1024
End Sub
Since Honeycomb:
B4X:
Sub GetFreeMem As Float
   Dim r As Reflector
   Dim MM, TM, FM, Total As Int
   r.Target = r.RunStaticMethod("java.lang.Runtime", "getRuntime", Null, Null)
   MM = r.RunMethod("maxMemory")
   FM = r.RunMethod("freeMemory")
   TM = r.RunMethod("totalMemory")
   Total = MM + FM - TM, Null, Null)
   Return Total / 1024
End Sub
 
Upvote 0
Top