libgdx _gpumem_alloc: mmap failed errno 12 Out of memory

Anything libgdx related goes here!

libgdx _gpumem_alloc: mmap failed errno 12 Out of memory

Postby saransh » Tue Jul 10, 2018 8:29 pm

Having an animation of 200 frames. Am getting this error.
sharedmem_gpumem_alloc: mmap failed errno 12 Out of memory

How to fix this. This is the animation actor that is being used
Code: Select all
public class AnimatedFullScreen extends Actor {

    public boolean startAnimation = true;
    public Sound sound;
    private OnAnimationComplete mOnAnimationCompleterListener;
    private Animation<TextureRegion> animation;
    private TextureAtlas atlas;
    private float scaleX, scaleY;
    private float px = 0, py = 0;
    private float animationWidth, animationHeight;
    private int type = 0;
    private float showTime;
    private boolean loop; //animation looping or not

    //default constructor
    public AnimatedFullScreen(String atlasName, boolean loop) {
        atlas = new TextureAtlas(Gdx.files.internal("animations/" + atlasName + ".atlas"));


        this.animation = new Animation<TextureRegion>(2 / 10f, atlas.getRegions());
        this.scaleX = CommonObjects.screenWidth / atlas.getRegions().get(0).getRegionWidth();
        this.scaleY = CommonObjects.screenHeight / atlas.getRegions().get(0).getRegionHeight();
        this.loop = loop;


    }
    /*
        type 0 default for default animation width and height
        type 1 for specific width and height
        other parameter usual meaning
     */

    public AnimatedFullScreen(String atlasName, boolean loop, float px, float py, boolean startAnimation, int type,
                              float animationWidth, float animationHeight) {
        atlas = new TextureAtlas(Gdx.files.internal("animations/" + atlasName + ".atlas"));
        this.animation = new Animation<TextureRegion>(4 / 10f, atlas.getRegions());
        this.scaleX = CommonObjects.screenWidth / atlas.getRegions().get(0).getRegionWidth();
        this.scaleY = CommonObjects.screenHeight / atlas.getRegions().get(0).getRegionHeight();
        this.loop = loop;
        this.px = px;
        this.py = py;
        this.startAnimation = startAnimation;
        this.type = type;
        this.animationWidth = animationWidth;
        this.animationHeight = animationHeight;

    }

    @Override
    public void act(float delta) {
        super.act(delta);
        showTime += delta;
    }

    @Override
    public void draw(Batch batch, float parentAlpha) {


        if (startAnimation) {

            batch.draw(animation.getKeyFrame(showTime, loop), px, py, 0, 0,
                    type == 0 ? animation.getKeyFrame(showTime).getRegionWidth() : animationWidth,
                    type == 0 ? animation.getKeyFrame(showTime).getRegionHeight() : animationHeight,
                    type == 0 ? scaleX : scaleY,
                    type == 0 ? scaleY : scaleY, 0);
        }

        //shows still image when animation not started
        else {
            batch.draw(animation.getKeyFrame(0, loop), px, py, 0, 0,
                    type == 0 ? animation.getKeyFrame(showTime).getRegionWidth() : animationWidth,
                    type == 0 ? animation.getKeyFrame(showTime).getRegionHeight() : animationHeight,
                    type == 0 ? scaleX : scaleY,
                    type == 0 ? scaleY : scaleY, 0);
        }

        //fires listener when animation completed
        if (animation.isAnimationFinished(showTime)) {
            if (mOnAnimationCompleterListener != null) {
                mOnAnimationCompleterListener.setNextScreen();


            }
        }

    }

    public void setListener(OnAnimationComplete listener) {
        mOnAnimationCompleterListener = listener;
    }
}

Works fine when trying out with half the frames. What is the ideal way to load animations and what is it that is causing the error.
saransh
 
Posts: 2
Joined: Wed Jan 24, 2018 7:45 am

Re: libgdx _gpumem_alloc: mmap failed errno 12 Out of memory

Postby evilentity » Wed Jul 11, 2018 6:43 am

Last ive checked memory is finite and 200 full screen textures are quite a lot to pack in there. There is a reason why movies are not stored as a ton of pngs. And are not loaded all at once.

You can try loading like 60 or something first and then load more as you go while disposing old frames. Or not use keyframe animation.
Looking for a freelancer? PM me!
evilentity
 
Posts: 4555
Joined: Wed Aug 24, 2011 11:37 am


Return to Libgdx

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], raeleus and 1 guest