projectM-visualizer / projectm

projectM - Cross-platform Music Visualization Library. Open-source and Milkdrop-compatible.
https://discord.gg/mMrxAqaa3W
GNU Lesser General Public License v2.1
3.37k stars 375 forks source link

Instance creation fails on some Android devices #788

Open protyposis opened 8 months ago

protyposis commented 8 months ago

Describe the bug

I am testing projectM 4.1.0 on a few Android devices. The projectm_create() call seems to fail on some of them, with the following errors:

device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindTexture:2200 GL error 0x500
device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindTexture:2200 GL error 0x500

It doesn't crash though, and following projectm_opengl_render_frame calls just don't render anything. There are no further errors.

When using the debug build, the app crashes immediately at instance creation with

device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindTexture:2200 GL error 0x500
/home/runner/work/projectm/projectm/src/libprojectM/ProjectM.cpp:216: void libprojectM::ProjectM::LoadIdlePreset(): assertion "m_activePreset" failed
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 3526 (GLThread 302), pid 3499 (rojectm_android)
device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindTexture:2200 GL error 0x500
pid: 3499, tid: 3526, name: GLThread 302  >>> com.github.projectm_android <<<
      #03 pc 00000000001e45f2  /data/app/~~He_o5QPBFnnIQzGw4CPYNQ==/com.github.projectm_android-GkXKDgCEHh5O_IsDoObXLQ==/lib/x86_64/libprojectM-4d.so (BuildId: 60346e06d5bd082c351491dae3427bc599f06743)
      #04 pc 00000000001e334b  /data/app/~~He_o5QPBFnnIQzGw4CPYNQ==/com.github.projectm_android-GkXKDgCEHh5O_IsDoObXLQ==/lib/x86_64/libprojectM-4d.so (BuildId: 60346e06d5bd082c351491dae3427bc599f06743)
      #05 pc 00000000001e2d2b  /data/app/~~He_o5QPBFnnIQzGw4CPYNQ==/com.github.projectm_android-GkXKDgCEHh5O_IsDoObXLQ==/lib/x86_64/libprojectM-4d.so (BuildId: 60346e06d5bd082c351491dae3427bc599f06743)
      #06 pc 00000000001e7548  /data/app/~~He_o5QPBFnnIQzGw4CPYNQ==/com.github.projectm_android-GkXKDgCEHh5O_IsDoObXLQ==/lib/x86_64/libprojectM-4d.so (BuildId: 60346e06d5bd082c351491dae3427bc599f06743)
      #07 pc 00000000001e74ca  /data/app/~~He_o5QPBFnnIQzGw4CPYNQ==/com.github.projectm_android-GkXKDgCEHh5O_IsDoObXLQ==/lib/x86_64/libprojectM-4d.so (projectm_create+58) (BuildId: 60346e06d5bd082c351491dae3427bc599f06743)
      #08 pc 00000000000016b4  /data/app/~~He_o5QPBFnnIQzGw4CPYNQ==/com.github.projectm_android-GkXKDgCEHh5O_IsDoObXLQ==/lib/x86_64/libjniwrapper.so (Java_com_github_projectm_1android_libprojectMJNIWrapper_onSurfaceCreated+164) (BuildId: faca253343119fef270b5a7c776d885dc2cc4d52)
      #16 pc 000000000000154a  [anon:dalvik-classes3.dex extracted in memory from /data/app/~~He_o5QPBFnnIQzGw4CPYNQ==/com.github.projectm_android-GkXKDgCEHh5O_IsDoObXLQ==/base.apk!classes3.dex] (com.github.projectm_android.RendererWrapper.onSurfaceCreated+58)

Using the release build and initializing a playlist with projectm_playlist_create, a crash doesn't happen until the first projectm_opengl_render_frame call:

terminating with uncaught exception of type libprojectM::Playlist::PlaylistEmptyException: Playlist is empty
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 3912 (GLThread 321), pid 3886 (rojectm_android)
pid: 3886, tid: 3912, name: GLThread 321  >>> com.github.projectm_android <<<
      #02 pc 000000000018b59b  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4.so (BuildId: d0a1c00f9f255efd5aa4eac827857e17fe9b3a42)
      #03 pc 000000000018b78e  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4.so (BuildId: d0a1c00f9f255efd5aa4eac827857e17fe9b3a42)
      #04 pc 000000000018b642  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4.so (BuildId: d0a1c00f9f255efd5aa4eac827857e17fe9b3a42)
      #05 pc 000000000018ad45  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4.so (BuildId: d0a1c00f9f255efd5aa4eac827857e17fe9b3a42)
      #06 pc 000000000018accc  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4.so (__cxa_throw+108) (BuildId: d0a1c00f9f255efd5aa4eac827857e17fe9b3a42)
      #07 pc 0000000000008a34  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4-playlist.so (BuildId: eb3fb18f084886f0e08e046c2d0fd21aae5c5e9e)
      #08 pc 000000000000b74d  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4-playlist.so (BuildId: eb3fb18f084886f0e08e046c2d0fd21aae5c5e9e)
      #09 pc 000000000012cbcf  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4.so (BuildId: d0a1c00f9f255efd5aa4eac827857e17fe9b3a42)
      #10 pc 000000000012d490  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libprojectM-4.so (BuildId: d0a1c00f9f255efd5aa4eac827857e17fe9b3a42)
      #11 pc 00000000000016a4  /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/lib/x86_64/libjniwrapper.so (Java_com_github_projectm_1android_libprojectMJNIWrapper_onDrawFrame+52) (BuildId: 52b09f57788ed9ccb15398abc7c21c0f61671bf6)
      #19 pc 00000000000014ce  [anon:dalvik-classes3.dex extracted in memory from /data/app/~~4i_HRvxSdxZQiiyMHb9iQQ==/com.github.projectm_android-TZ-Lp0o8srLa7TlgfgPtwg==/base.apk!classes3.dex] (com.github.projectm_android.RendererWrapper.onDrawFrame+58)

When additionally loading presets into the playlist, I receive a projectm_playlist_preset_switch_failed_event on the first render call with error message std::exception, and afterwards it seems to enter an infinite loop trying to load the idle preset idle://Geiss & Sperl - Feedback (projectM idle HDR mix).milk and again failing all the time with error message std::exception.

Tested devices:

kblaschke commented 8 months ago

OpenGL ES error 0x500 is "GL_INVALID_ENUM", which points to some flag being used that the particular OpenGL implementation on that device does not understand.

Please make sure the device properly supports and uses OpenGL ES 3.1 as the selected profile to run projectM. Any previous version will not work due to projectM making use of OpenGL ES 3.1 functionality.

Your debug output suggests you're using a OpenGL ES 2.0 rendering profile. I suggest checking the OpenGL version after context creation to make sure it's really "3.1 ES" and not some older fallback version.

In the release build, the crash in the playlist library will probably happen because the projectM instance creation fails without sigabort being called as an assertion and projectm_create() returns NULL or an invalid pointer. Passing this to the playlist manager will cause the projectM callback registration to crash.

protyposis commented 8 months ago

Thank you, you're right, the version was set to 2.0 (it still worked on most tested devices). Increasing to v3 (it is not possible to explicitly request minor versions) makes it work on the API 30 emulator :)

It still doesn't work on the Pixel phone (which supports up to 3.2), on which I noticed it doesn't log the 0x500 error, so I might just have erroneously assumed that it's affected by the same issue. Need to investigate further.

protyposis commented 7 months ago

On the Pixel phone, it seems that LoadIdlePreset() fails in the init function (exception message is unfortunately just std::exception). I traced it to a failing member initialization at https://github.com/projectM-visualizer/projectm/blob/50c64d4e653a9f6dcb97f59f377b8796eed278fe/src/libprojectM/MilkdropPreset/MilkdropPreset.cpp#L47-L56 but got stuck here due to my limited C++ experience.

protyposis commented 7 months ago

Further pinned it down to m_motionVectors -> m_presetState -> globalMemory, where it seems to fail at the projectm_eval_memory_buffer_create() call.

kblaschke commented 7 months ago

If this call fails, the only reason I could see here is an out-of-memory issue, as the function is a single line with calloc() that reserves a small array of pointers (1024 bytes on 64-bit platforms) and initializes the area with zeroes. Since I don't have any Android experience or any test systems, I can also just guess on this one - never happened on any other platform I've tested on, including the Raspbery Pi 5.