Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 19 Aug 2011
Offline Last Active Mar 02 2013 10:09 AM

Topics I've Started

Problems with playing sounds using SoundPool

13 February 2013 - 04:04 AM

In my Android game, I am playing short sound effects using AudioManager and SoundPool.


While this works fine on Samsung Galaxy Tab 10.1, when I ported the game to Samsung Galaxy SIII, I am experiencing strange lock-ups of the screen and crashes of the application with re-booting of the phone, when I am trying to play the sound from the SoundPool.


It behaves quite erratically and one of 4 things happen (in no particular order):


(1) Application starts as normal and all sounds play normally.


(2) Application crashes completely and mobile reboots.


(3) Application freezes shortly (3-5 seconds) upon trying to play the sound, then continues normally, but sounds don't work.


(4) Application starts as normal, but none of the sounds plays. *


* There is a strange twist to the 4th case. None of the sounds plays, but when I activate game background music (which plays via MediaPlayer, not via AudioManager/SoundPool) this somehow 'flushes down' the stuck sound effects which should play at the beginning of the game, and now they all catch-up and play at once. This 'flushing down' somehow returns everything back to normal and from this point on all the sound effects from the SoundPool play normally, as they should.


The error which I am getting is:


AudioTrack: obtainBuffer timed out (is the CPU pegged?) "CPU pegged" what the hell does it even mean ??? unsure.png


Note that the problems happen at the point in the game when I am attempting to play the sounds from the soundpool by SoundPool.play, not when I am loading them by SoundPool.load.


I tried just about everything and now I am at the end of my wits. Did anybody have the same problem? Any help is highly appreciated.



glRotatef behaves strange

24 July 2012 - 09:57 AM

I have several 2D objects (simple squares with bitmaps on them) which I need to rotate on y axis (i.e. from left to right) all at the same angle.

However, when I use glRotatef command, the objects on the right side of the screen are rotated the most, and progressively towards the left side of the screen, they rotate less and less.

If I have let say 15 objects side-by-side, the difference in rotation between the leftmost and rightmost object is quite substantial and clearly visible.

I assume this is something to do with the perspective, but cannot figure out what I am doing wrong.

Just for interest, if I rotate the same objects on x axis (i.e. from forward to backward) the angle is the same for all of them !

Anybody knows how to achieve rotation at the same angle for all the objects on y axis ?

Thanks in advance for any suggestions.

How to pass context into onDrawFrame

31 January 2012 - 10:23 AM

I am designing a game in Open GLES on Android in Java.

Obviously I am using lots of textures and soon I will run out of memory.

I am quite new to Android and Java, but I figured that the easiest way to go round this problem is to destroy the objects with bitmaps, which I don't need at the moment, let the garbage collector reclaim the memory which they occupied, then re-create those objects at the late stage when I again need the respective textures.

Something like this:

background = null;

then when I need the textures in background object:

background = new Background(context);

seems pretty straighforward, except that is, that the context (which I need for my class background to function, as it loads the textures from it via BitmapFactory) is not passed into onDrawFrame(GL10 gl) function where my main game loop is and where I need it !

If I try to add context as a second parameter after GL10 gl, I get an error - this does not seem to be possible.

Does anybody know how to pass context into onDrawFrame, or other way how to clear the context objects from memory and then reinstate them again ?

Thanks in advance for any help.

Problem with loading bitmaps into Android Application

31 January 2012 - 09:37 AM

I am designing an Android game, and as the games go, they contain lots of bitmaps.

Mine is not exception and I am loading them via BitmapFactory by the following instruction:

bitmap = BitmapFactory.decodeStream(context.getResources().openRawResource(imageFileIDs[IndexOfBitmapHere]));

Everything goes great, until certain amount of calls to the above instruction - then the app keels over with the Out Of Memory message.

Thing is, that after uploading let say 40 bitmaps of the same size, I have still 70% of Memory Free.

Then I upload just one more additional bitmap of the same size, which should take me comfortably to some 69% and instead all goes bang - OOM !!!

The garbage collector suddenly reports it has only 3-2-1% of memory left, then OOM crash. Posted Image

There is obviously some bug in Android (I am running this on 3.0) and I cannot figure out what it is.

I have tried just about everything and now I am stuck with this annoying issue already 2 weeks.

Does anybody know what causes it and what is the way around ?

Any help is highly appreciated.

How to roll texture around 2D object (square)

12 November 2011 - 03:36 PM

Anybody knows how to roll a texture over the face of an object in OpenGL ES ?

(not rotate the whole object, just roll the texture over the object's face)

It means that the topmost line of pixels will be removed, all lines will be shifted 1 pixel up, and the topmost line of pixels will be added at the very bottom, etc, etc... until the texture ends up in original state.

That will cause the rolling effect of texture over the face of an object, as demonstrated below.

from this:


to this: