Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pygame.display.set_mode runs out of memory #331

Closed
gunsmoker70 opened this issue Feb 18, 2015 · 9 comments
Closed

pygame.display.set_mode runs out of memory #331

gunsmoker70 opened this issue Feb 18, 2015 · 9 comments

Comments

@gunsmoker70
Copy link

I'm able to build python-for-android and the touchtracer demo works fine for me.
However, when I try an application that uses pygame, I get an "Out of memory error" in the logcat upon the pygame.display.set_mode statement to set the screen resolution which is close to the beginning of the program after the pygame.init statement. I don't have this problem with the pygame subset for android (PGS4a-0.9.6) and when running python/pygame on Windows or RaspberryPi.
I need to build python-for-android myself in order to include the openssl package which PGS4A does not include.

I tried various things - NDK 8c, 9, 10d, Android API levels 14, 20, JDK 1.8.0, cython 0.20 with no success. I built on a debian x86 machine updated to the latest stable level.
I get the same problem whether I specify openssl, pil, and kivy modules as in the README.txt file or android, pygame, and pyjnius modules to build.

I tried tracing that out-of-memory message and if I'm not incorrect, it's coming from one of the camera C files in pygame where it tries to calloc a buffer during some initialization. I don't need camera support and I intend to comment out the camera initialization to see if it will get any further.

Any help will be greatly appreciated.

@gunsmoker70
Copy link
Author

I started looking into disabling the camera initialization. I found that the camera code was not included in the build (see the Setup file) so it must be something else.

@gunsmoker70
Copy link
Author

Looked into the problem some more. I call pygame.display.Info before that and it works correctly.
I put a printf statement in pygame.display.set_mode and it didn't get to it so I'm thinking there must be something wrong with how this function is declared or called.
Not sure if this applies to how python module symbols are looked up, but since there is no name space, I guessed there might be another global symbol with the set_mode name and that could cause the linker to do bad things. So I changed the name, but still could not get to my print statement inside for the "pygame.error: Out of memory error" prior to that.

@tito
Copy link
Member

tito commented Feb 18, 2015

Touchtracer works, but pygame is used as a base for our Window provider / touch event. Memory error on a set_mode can just highlight some issue with your code prior the Window initialization? Maybe you could share your app source code or a reproducible snippet?

@gunsmoker70
Copy link
Author

Thanks for the reply. Here is a test case. For some reason the indentations are not shown unless the post is in edit mode.

import pygame

try:
    import android
    import android.mixer as mixer
except ImportError:
    import pygame.mixer as mixer
    android = None

def main():
    pygame.init()
    info = pygame.display.Info()
    print info
    # Out of memory in logcat at next line:
    screen = pygame.display.set_mode ((640,480))
    if android:
        android.init()
        android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
    pygame.quit()

#To run on PC
if __name__ == "__main__":
    main()

The size of the window doesn't seem to matter. It runs out of memory also for 1280x720 which is the native resolution of the device.

Here is the logcat from my phone. It's a Samsung Galaxy S5 mini with Android version 4.4.2:

--------- beginning of /dev/log/system
V/python  (15068): metadata fullscreen is1
I/python  (15068): extracting libpymodules.so
I/python  (15068): extracting lib/
I/python  (15068): extracting lib/python27.zip
I/python  (15068): extracting lib/python2.7/
I/python  (15068): extracting lib/python2.7/config/
I/python  (15068): extracting lib/python2.7/config/Setup
I/python  (15068): extracting lib/python2.7/config/config.c.in
I/python  (15068): extracting lib/python2.7/config/Setup.local
I/python  (15068): extracting lib/python2.7/config/Setup.config
I/python  (15068): extracting lib/python2.7/config/Makefile
I/python  (15068): extracting lib/python2.7/config/config.c
I/python  (15068): extracting lib/python2.7/config/install-sh
I/python  (15068): extracting lib/python2.7/site-packages/
I/python  (15068): extracting lib/python2.7/site-packages/README
I/python  (15068): extracting lib/python2.7/site-packages/jnius_config.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/
I/python  (15068): extracting lib/python2.7/site-packages/pygame/mouse.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/draw.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/sysfont.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/version.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/color.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/cursors.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/pygame_icon.tif
f
I/python  (15068): extracting lib/python2.7/site-packages/pygame/pixelarray.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/colordict.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/image.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/font.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/midi.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/sprite.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/rwobject.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/joystick.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/gfxdraw.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/constants.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/rect.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/pygame.ico
I/python  (15068): extracting lib/python2.7/site-packages/pygame/_arraysurfarray
.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/locals.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/base.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/surflock.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/display.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/pkgdata.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/key.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/bufferproxy.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/time.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/mask.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/imageext.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/surface.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/transform.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/overlay.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/fastevent.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/compat.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/__init__.pyo
I/python  (15068): extracting lib/python2.7/site-packages/pygame/event.so
I/python  (15068): extracting lib/python2.7/site-packages/pygame/threads/
I/python  (15068): extracting lib/python2.7/site-packages/pygame/threads/__init_
_.pyo
I/python  (15068): extracting lib/python2.7/site-packages/jnius/
I/python  (15068): extracting lib/python2.7/site-packages/jnius/jnius.so
I/python  (15068): extracting lib/python2.7/site-packages/jnius/reflect.pyo
I/python  (15068): extracting lib/python2.7/site-packages/jnius/__init__.pyo
I/python  (15068): extracting lib/python2.7/site-packages/android/
I/python  (15068): extracting lib/python2.7/site-packages/android/broadcast.pyo
I/python  (15068): extracting lib/python2.7/site-packages/android/_android_billi
ng.so
I/python  (15068): extracting lib/python2.7/site-packages/android/_android_sound
.so
I/python  (15068): extracting lib/python2.7/site-packages/android/_android.so
I/python  (15068): extracting lib/python2.7/site-packages/android/activity.pyo
I/python  (15068): extracting lib/python2.7/site-packages/android/billing.pyo
I/python  (15068): extracting lib/python2.7/site-packages/android/runnable.pyo
I/python  (15068): extracting lib/python2.7/site-packages/android/__init__.pyo
I/python  (15068): extracting lib/python2.7/site-packages/android/mixer.pyo
I/python  (15068): extracting lib/python2.7/lib-dynload/
I/python  (15068): extracting lib/python2.7/lib-dynload/imageop.so
I/python  (15068): extracting lib/python2.7/lib-dynload/syslog.so
I/python  (15068): extracting lib/python2.7/lib-dynload/_io.so
I/python  (15068): extracting lib/python2.7/lib-dynload/unicodedata.so
I/python  (15068): extracting include/
I/python  (15068): extracting include/python2.7/
I/python  (15068): extracting include/python2.7/pyconfig.h
I/python  (15068): extracting main.pyo
I/python  (15068): Starting audio thread
I/python  (15068): Initialize Python for Android
I/python  (15068): ['/data/data/org.test/files/lib/python2.7/site-packages', '/d
ata/data/org.test/files/lib/site-python']
I/python  (15068): Android path ['/data/data/org.test/files/lib/python27.zip', '
/data/data/org.test/files/lib/python2.7', '/data/data/org.test/files/lib/python2
.7/lib-dynload', '/data/data/org.test/files/lib/python2.7/site-packages', '/stor
age/emulated/0/org.test']
I/python  (15068): Android kivy bootstrap done. __name__ is __main__
I/python  (15068): Run user program, change dir and execute main.py
I/python  (15068): main.py:1: RuntimeWarning: import cdrom: No module named cdro
m
I/python  (15068): (ImportError: No module named cdrom)
I/python  (15068): <VideoInfo(hw = 1, wm = 0,video_mem = 131072
I/python  (15068):           blit_hw = 1, blit_hw_CC = 1, blit_hw_A = 1,
I/python  (15068):           blit_sw = 0, blit_sw_CC = 0, blit_sw_A = 0,
I/python  (15068):           bitsize  = 16, bytesize = 2,
I/python  (15068):           masks =  (63488, 2016, 31, 0),
I/python  (15068):           shifts = (11, 5, 0, 0),
I/python  (15068):           losses =  (3, 2, 3, 0),
I/python  (15068):           current_w = 1280, current_h = 720
I/python  (15068): >
I/python  (15068): Traceback (most recent call last):
I/python  (15068):   File "/home/tpetrov/test/main.py", line 24, in <module>
I/python  (15068):   File "/home/tpetrov/test/main.py", line 15, in main
I/python  (15068): pygame.error: Out of memory

@gunsmoker70
Copy link
Author

This is the logcat I got from a Nexus 4 simulator. It didn't get as far as the phone did to print the info variable in the test case.

I/ActivityManager( 521): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=org.test/org.renpy.android.PythonActivity} from pid 622
W/WindowManager( 521): Failure taking screenshot for (256x399) to layer 21010
D/dalvikvm( 1127): Not late-enabling CheckJNI (already on)
I/ActivityManager( 521): Start proc org.test:python for activity org.test/org.renpy.android.PythonActivity: pid=1127 uid=10040 gids={1015}
I/WindowManager( 521): createSurface Window{41a482b0 Starting org.test paused=false}: DRAW NOW PENDING
W/NetworkManagementSocketTagger( 521): setKernelCountSet(10040, 1) failed with errno -2
D/dalvikvm( 521): GC_CONCURRENT freed 534K, 10% free 16647K/18439K, paused 181ms+115ms
V/python ( 1127): metadata fullscreen is1
I/SDLSurface( 1127): Surface will NOT be transparent
V/Python ( 1127): Extracting private assets.
W/ActivityManager( 521): Launch timeout has expired, giving up wake lock!
D/dalvikvm( 1127): GC_FOR_ALLOC freed 54K, 2% free 14068K/14339K, paused 551ms
I/dalvikvm-heap( 1127): Grow heap (frag case) to 14.806MB for 1048592-byte allocation
D/dalvikvm( 1127): GC_FOR_ALLOC freed <1K, 3% free 15091K/15431K, paused 255ms
I/python ( 1127): extracting libpymodules.so
D/dalvikvm( 1127): GC_CONCURRENT freed 4K, 3% free 15122K/15431K, paused 72ms+44ms
I/WindowManager( 521): createSurface Window{41a82060 org.test/org.renpy.android.PythonActivity paused=false}: DRAW NOW PENDING
D/dalvikvm( 521): GREF has increased to 401
I/WindowManager( 521): createSurface Window{41a85a68 SurfaceView paused=false}: DRAW NOW PENDING
D/libEGL ( 1127): Emulator without GPU support detected. Fallback to software renderer.
D/libEGL ( 1127): loaded /system/lib/egl/libGLES_android.so
W/ActivityManager( 521): Activity idle timeout for ActivityRecord{41b13ac8 org.test/org.renpy.android.PythonActivity}
I/SDLSurface( 1127): Choose egl configuration
I/SDLSurface( 1127): Try to use graphics config R8G8B8A8S8
I/SDLSurface( 1127): Try to use graphics config R5G6B5S8
E/SDLSurface( 1127): Unable to find a correct surface for this device !
E/JavaBinder( 1127): Unknown binder error code. 0xfffffff7
E/JavaBinder( 1127): Unknown binder error code. 0xfffffff7
E/ViewRootImpl( 1127): IllegalArgumentException locking surface
E/ViewRootImpl( 1127): java.lang.IllegalArgumentException
E/ViewRootImpl( 1127): at android.view.Surface.lockCanvasNative(Native Method)
E/ViewRootImpl( 1127): at android.view.Surface.lockCanvas(Surface.java:76)
E/ViewRootImpl( 1127): at android.view.ViewRootImpl.draw(ViewRootImpl.java:1924)
E/ViewRootImpl( 1127): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1613)
E/ViewRootImpl( 1127): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
E/ViewRootImpl( 1127): at android.os.Handler.dispatchMessage(Handler.java:99)
E/ViewRootImpl( 1127): at android.os.Looper.loop(Looper.java:137)
E/ViewRootImpl( 1127): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/ViewRootImpl( 1127): at java.lang.reflect.Method.invokeNative(Native Method)
E/ViewRootImpl( 1127): at java.lang.reflect.Method.invoke(Method.java:511)
E/ViewRootImpl( 1127): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/ViewRootImpl( 1127): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/ViewRootImpl( 1127): at dalvik.system.NativeStart.main(Native Method)
E/JavaBinder( 1127): Unknown binder error code. 0xfffffff7
W/NetworkManagementSocketTagger( 521): setKernelCountSet(10005, 0) failed with errno -2
E/JavaBinder( 1127): Unknown binder error code. 0xfffffff7
E/JavaBinder( 1127): Unknown binder error code. 0xfffffff7
E/ViewRootImpl( 1127): IllegalArgumentException locking surface
E/ViewRootImpl( 1127): java.lang.IllegalArgumentException
E/ViewRootImpl( 1127): at android.view.Surface.lockCanvasNative(Native Method)
E/ViewRootImpl( 1127): at android.view.Surface.lockCanvas(Surface.java:76)
E/ViewRootImpl( 1127): at android.view.ViewRootImpl.draw(ViewRootImpl.java:1924)
E/ViewRootImpl( 1127): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1613)
E/ViewRootImpl( 1127): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2418)
E/ViewRootImpl( 1127): at android.os.Handler.dispatchMessage(Handler.java:99)
E/ViewRootImpl( 1127): at android.os.Looper.loop(Looper.java:137)
E/ViewRootImpl( 1127): at android.app.ActivityThread.main(ActivityThread.java:4340)
E/ViewRootImpl( 1127): at java.lang.reflect.Method.invokeNative(Native Method)
E/ViewRootImpl( 1127): at java.lang.reflect.Method.invoke(Method.java:511)
E/ViewRootImpl( 1127): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/ViewRootImpl( 1127): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/ViewRootImpl( 1127): at dalvik.system.NativeStart.main(Native Method)
E/JavaBinder( 1127): Unknown binder error code. 0xfffffff7
E/JavaBinder( 1127): Unknown binder error code. 0xfffffff7
I/WindowManager( 521): WIN DEATH: Window{41a82060 org.test/org.renpy.android.PythonActivity paused=false}
I/ActivityManager( 521): Process org.test:python (pid 1127) has died.
W/ActivityManager( 521): Force removing ActivityRecord{41b13ac8 org.test/org.renpy.android.PythonActivity}: app died, no saved state
W/NetworkManagementSocketTagger( 521): setKernelCountSet(10040, 0) failed with errno -2
W/WindowManager( 521): Force-removing child win Window{41a85a68 SurfaceView paused=false} from container Window{41a82060 org.test/org.renpy.android.PythonActivity paused=false}
W/WindowManager( 521): Failed looking up window
W/WindowManager( 521): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@41937c90 does not exist
W/WindowManager( 521): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7029)
W/WindowManager( 521): at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7020)
W/WindowManager( 521): at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1439)
W/WindowManager( 521): at android.os.BinderProxy.sendDeathNotice(Binder.java:417)
W/WindowManager( 521): at dalvik.system.NativeStart.run(Native Method)
I/WindowManager( 521): WIN DEATH: null
W/NetworkManagementSocketTagger( 521): setKernelCountSet(10005, 1) failed with errno -2
I/WindowManager( 521): createSurface Window{41ac7e48 com.android.launcher/com.android.launcher2.Launcher paused=false}: DRAW NOW PENDING
W/InputManagerService( 521): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@418b52a0
W/ThrottleService( 521): unable to find stats for iface rmnet0

@gunsmoker70
Copy link
Author

I wonder if it has something to do with a p4a build error I noticed - there was a message that the compiler could not find the jnius.c file and then the build took a couple of secconds on the next line and it was compiling that file following that. It seemed awkward as if the build was trying to find the file here and there until it succeeded.

@gunsmoker70
Copy link
Author

Looked some more into this. It's coming from src/jni/src/video/SDL_SetVideoMode.c
If I set the pygame.HWSURFACE flag in the pygame.display.set_mode call, I don't get the memory error and the test case exits correctly. However, with the actual program it gets hosed up later to the point that the phone stops responding, there is no logcat output or the app is aborted and when the phone comes back, the layout is horizontal instead of vertical.
In other words, something is messed in in the SDL layer or below.
How is the video mode set up with the kivy apps (e.g. touchtracer)?

@gunsmoker70
Copy link
Author

I got myself unblocked by copying the sdl libraries from pgs4a-0.9.6 into the dist/default/libs/armeabi directory.
Still not sure why they did not build right for me. I tried many versions of the NDK and SDK API levels without success. My host is the current Debian.
I'm using also mysql_connector and I noticed that the version in this branch (1.x) does not work with the latest 5.5 server. The latest connector version is 2.x. Pasting it in the site-packages directory solves the problem.

@tito
Copy link
Member

tito commented Mar 6, 2015

Now i understand. We don't aim to let you use the pygame directly, maybe that's why. The java part initialize GL, and require pygame/SDL to initialize it too. We don't provide pygame-based app directly, but that's what pgs4a provide. If you have been able to make your own changes upon that, that's good, but we don't provide it yet :)

@tito tito closed this as completed Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants