This is a free for all forum, not your personal help line.
I never doubted that / thought that, respectively.
This is a free for all forum, not your personal help line.
Was there anything particularly different in the scenes for the log where you have the successful result and the crash? or were they exactly the same test?
For clarity, I am posting 2 logs in following two posts.
1st log is where the game starts fine, about 50 or so textures ranging in size from 80x80 to 1280x752 load just fine and everything works great. This works whether I put to allocation ridiculously small numbers, or their thousedfold values (width * height * 4 does not work, that crashes immediately, but I put there anything from 12 * 4 to width * 4 and it did not seem to make an iota of difference - all textures loaded and game ran). As you can see though there is something strange going on there - it seems like Android is running out of puff there, having 1-2-3% of memory free, then suddenly reclaims up to 71%!
2nd log is the same situation, I did not change memory allocation, only added one more object loading one more 1280x752 texture. That is where it crashes.
Was it running on the phone or the emulator?
It looks like a pre load of all the resources before starting a level (which is definately the right thing to do).
In fact, I am trying to load all the bitmaps which I need for the whole game. I don't think this is the right thing to do, I would much more prefer to load only the bitmaps which I need for the first level, and load bitmaps for another level as and when I start that particular level, but I don't know how to do it either - to load the bitmaps later, I need the Context and I don't know how to pass it into onDrawFrame function, where is my main game loop (as explained in my other post http://www.gamedev.n...__fromsearch__1)
public void onDrawFrame(GL10 gl) {
endTime = System.currentTimeMillis();
long dt = endTime - startTime;
int fps = Math.round(1000f / dt);
if (fps < TargetFps) {
try {
Thread.sleep(TargetFps - fps);
} catch (InterruptedException e) {}
}
startTime = System.currentTimeMillis();
// update the game state
// render the game using the gl context
}
// This is just off the cuff code, i don't expect it to compile it's just to give you an idea.
public class GameActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyGameLevel level = createTheLevel();
GlSurfaceView view = // Get a hold of your view or create it
Renderer r = new LevelRenderer(level);
view.setRenderer(r);
// If this causes noticeable issues on starting the activity don't do it
Runtime.getRuntime().gc();
}
private MyGameLevel createTheLevel() {
// Create a level it can load the textures
MyGameLevel level = new MyGameLevel();
// Load all the textures i need (this could be done by the level class this is just an example for arguments sake)
MyTextureManager.instance().loadBitmap(context, R.drawable.whatever);
MySoundManager.instance().loadSound(context, R.raw.sound1);
// etc...but all your resources are loaded
}
}
public class LevelRenderer extends Renderer {
MyGameLevel level;
public LevelRenderer(MyGameLevel l) {
level = l;
}
@Override
public void onDrawFrame(GL10 gl) {
// Game loop
level.update(dt);
level.render(gl);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// You can do this or you can wait until you call level.render before binding the textures, your implementation will suit your needs
level.bindGlTextures(gl, config);
}
}
public class MyGameLevel() {
public void bindGlTextures(Gl10 gl, EGLConfig config) {
// here you can use the MyTextureManager to get the bitmaps and bind them to your gl context as you call this as soon as the surface is
// created...if you wan't to, delay this until the render call it is fine the important thing is the Textures exist already in the manager in bitmap form.
// something like ....can't quite remember the syntax
gl.bindTexture(GL_TEXTURE_2D, MyTextureManager.instance().getBitmap(R.drawable.whatever);
}
public void render(GL10 gl) { // draw the level }
public void update(long dt) { // update the level }
}
The method to load a bitmap takes the context which is readily available in the Activity.