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.3k stars 368 forks source link

[APP BUG] Unexpected crash of projectM visualizer in a custom Android app (Android 13, arm64-v8a) #825

Closed Kyborg2011 closed 1 month ago

Kyborg2011 commented 2 months ago

Please confirm the following points:

Affected Application

Third-Party Integration (Kodi, VLC, etc. - please specify below)

Affected Version

4.1.1

Operating System

Other, all or not relevant

Additional Application Details

I have downloaded projectM from current Github repo. To build it for Android I have used custom script (written by myself):

#!/bin/bash

ANDROID_SDK="/Users/aroslavivanov/Library/Android/sdk"
ANDROID_NDK="${ANDROID_SDK}/ndk/26.1.10909125"
CMAKE_MAKE_PROGRAM="${ANDROID_SDK}/cmake/3.22.1/bin/ninja"
MIN_SDK_VERSION=24

cd projectm/build

function build_projectm {
    ABI=$1
    mkdir -p ${ABI}

    cmake -S .. -B${ABI} \
        -G "Ninja Multi-Config" \
        -DCMAKE_SYSTEM_NAME=Android \
        -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} \
        -DBUILD_SHARED_LIBS=ON \
        -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
        -DANDROID_ABI=${ABI} \
        -DANDROID_PLATFORM=android-${MIN_SDK_VERSION} \
        -DANDROID_ARM_NEON=TRUE \
        -DANDROID_TOOLCHAIN=clang \
        -DANDROID_STL=c++_shared \
        -DCMAKE_BUILD_TYPE=Release \
        -DBUILD_TESTING=NO \
        -DCMAKE_VERBOSE_MAKEFILE=YES \
        -DENABLE_SDL_UI=OFF \
        -DENABLE_PLAYLIST=OFF

    cmake --build ${ABI} --config "Release" --parallel

    mkdir -p ../../../distribution/libprojectM/lib/${ABI}
    cp ${ABI}/src/libprojectM/libprojectM-4.so ../../../distribution/libprojectM/lib/${ABI}/
}

build_projectm arm64-v8a
build_projectm armeabi-v7a
build_projectm x86
build_projectm x86_64

mkdir -p ../../../distribution/libprojectM/include/
cp -r ../src/api/include/projectM-4 ../../../distribution/libprojectM/include/
cp arm64-v8a/src/api/include/projectM-4/version.h ../../../distribution/libprojectM/include/projectM-4/
cp arm64-v8a/src/api/include/projectM-4/projectM_export.h ../../../distribution/libprojectM/include/projectM-4/ 

Type of Defect

Crash (unexpected closing, OS crash dialog)

Log Output

* * * * * * * * * * * * * * * *
Build fingerprint: 'samsung/z3sxxx/z3s:13/TP1A.220624.014/G988BXXSKHXEA:user/release-keys'
Revision: '23'
ABI: 'arm64'
Processor: '-1'
Timestamp: 2024-07-08 02:25:37.070860665+0300
Process uptime: 749s
Cmdline: xyz.luceolab.cadenza
pid: 28185, tid: 30873, name: GLThread 212  >>> xyz.luceolab.cadenza <<<
uid: 10635
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000001398
    x0  0000000000000000  x1  0000000000000000  x2  0000000000000001  x3  0000000000000042
    x4  0000000000000021  x5  8080800000000000  x6  000000720a31e000  x7  000000000091ba84
    x8  0000000000000437  x9  abaedb473472a0b3  x10 000000000000001e  x11 0101010101010101
    x12 0000006e1ba3c370  x13 0000000000000015  x14 0000000000000000  x15 00004b6923618e7e
    x16 0000006e63cb6b88  x17 0000006ee398c2dc  x18 0000006e195b2000  x19 000000708c653ee0
    x20 0000000000000000  x21 000000705c718398  x22 00000071ffea22d0  x23 0000006e1ba3f000
    x24 0000006e1ba3dcb0  x25 000000702c60e4a0  x26 000000000000106e  x27 00000071f3b89618
    x28 0000006e1ba3db80  x29 0000006e1ba3bb20
    lr  0000006ee398b2e4  sp  0000006e1ba3bb20  pc  0000006ee398c930  pst 0000000060000000
backtrace:
      #00 pc 00000000000bf930  /data/app/~~q36gqkCrGczFUephpmm6YQ==/xyz.luceolab.cadenza-czZPOBWmwXhqKMN4NApMfQ==/base.apk!libprojectM-4.so (BuildId: 7620354dafc62cc261d937f46950cc2e44f767f9)
      #01 pc 00000000000be2e0  /data/app/~~q36gqkCrGczFUephpmm6YQ==/xyz.luceolab.cadenza-czZPOBWmwXhqKMN4NApMfQ==/base.apk!libprojectM-4.so (BuildId: 7620354dafc62cc261d937f46950cc2e44f767f9)
      #02 pc 00000000001b1094  /data/app/~~q36gqkCrGczFUephpmm6YQ==/xyz.luceolab.cadenza-czZPOBWmwXhqKMN4NApMfQ==/base.apk!libaudio_engine.so (cadenza::MilkDropVisualizer::RenderFrame()+24) (BuildId: 2f3d01ff704681031c4b73a0e18eec2b183ed391)
      #03 pc 00000000001c26f0  /data/app/~~q36gqkCrGczFUephpmm6YQ==/xyz.luceolab.cadenza-czZPOBWmwXhqKMN4NApMfQ==/base.apk!libaudio_engine.so (cadenza::SoxPlayerApp::MilkDropVisualizerRenderFrame()+104) (BuildId: 2f3d01ff704681031c4b73a0e18eec2b183ed391)
      #04 pc 00000000001d03c0  /data/app/~~q36gqkCrGczFUephpmm6YQ==/xyz.luceolab.cadenza-czZPOBWmwXhqKMN4NApMfQ==/base.apk!libaudio_engine.so (MilkDropVisualizerRenderFrame(_JNIEnv*, _jobject*)+28) (BuildId: 2f3d01ff704681031c4b73a0e18eec2b183ed391)
      #05 pc 0000000000351e30  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: ddcc440d4609d2099db9d20895487a78)
      #06 pc 000000000033b3a4  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+612) (BuildId: ddcc440d4609d2099db9d20895487a78)
      #07 pc 0000000000511658  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, bool, art::JValue*)+1976) (BuildId: ddcc440d4609d2099db9d20895487a78)
      #08 pc 00000000004910c4  /apex/com.android.art/lib64/libart.so (void art::interpreter::ExecuteSwitchImplCpp<false>(art::interpreter::SwitchImplContext*)+1012) (BuildId: ddcc440d4609d2099db9d20895487a78)
      #09 pc 00000000003545d8  /apex/com.android.art/lib64/libart.so (ExecuteSwitchImplAsm+8) (BuildId: ddcc440d4609d2099db9d20895487a78)
      #10 pc 000000000000b298  [anon:dalvik-classes6.dex extracted in memory from /data/app/~~q36gqkCrGczFUephpmm6YQ==/xyz.luceolab.cadenza-czZPOBWmwXhqKMN4NApMfQ==/base.apk!classes6.dex] (xyz.luceolab.cadenza.player.PlaybackManager.milkdropVisualizerRenderFrame+0)
      #11 pc 000000000036e6ec  /apex/com.android.art/lib64/libart.so (art::interpreter::Execute(art::Thread*, art::CodeItemDataAccessor const&, art::ShadowFrame&, art::JValue, bool, bool) (.__uniq.112435418011751916792819755956732575238.llvm.9545667076320299271)+232) (BuildId: ddcc440d4609d2099db9d20895487a78)
      #12 pc 0000000000512324  /apex/com.android.art/lib64/libart.so (bool art::interpreter::DoCall<false>(art::ArtMethod*, art::Thread*, art::ShadowFrame&, art::Instruction const*, unsigned short, bool, art::JValue*)+5252) (BuildId: ddcc44

Describe the Issue

Hello, guys, I have gotten such an error (null pointer dereference) after call: projectm_opengl_render_frame on Android 13 device (Samsung Galaxy S20 Ultra), arm64-v8a. In general other calls run just fine, for example, projectm_create(); returned not null value (so, as I understand creation of instance runs successfully), projectm_pcm_add_int16 and setting window sizes - everything works without any crashes/errors.

I have tried two ways: if before frame rendering I have not loaded a preset - I have gotten crash when frame rendering begins, if before frame rendering I have tried to load a preset (from file or from string - the same) I have gotten crash immediately, so preset loading crashed practically the same way as a rendering phase (error the same, just memory addr another).

Please, help me with such an issue. Maybe I have done an error when tried to build projectM for Android, maybe I do not rightly understood the flow of a library or an api…

My simple test class to use projectM you can see here: https://gist.github.com/Kyborg2011/1ffabfbfcee6383a55c1812f3ab70605

The whole tombstone crash logs I have attached as a file.

Thank you, guys, in advance!

tombstone_14.txt

Kyborg2011 commented 1 month ago

When I created a Debug build of projectm I have gotten such an error (when creating a projectm instance):

/Users/aroslavivanov/.ssh/dev/cadenza-music-player/gen-libs/projectm/src/libprojectM/ProjectM.cpp:215: void libprojectM::ProjectM::LoadIdlePreset(): assertion "m_activePreset" failed
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 7659 (GLThread 624), pid 7463 (uceolab.cadenza)

Anyone can help me with that? I have seen in other issues that some devs already gotten such an error, but I do not see any solution about such problem...

rullinoiz commented 1 month ago

i am also getting this issue, i included version 4.1.0 into my android app's build process and when running it also gives me this error, this happens when instantiating the ProjectM object

hack-s commented 1 month ago

I have seen similar errors when calling projectm_create() without having an OpenGL context associated with the calling thread. Make sure that you are setting up OpenGL first (create a GL context and make it current to the thread) before calling the projectM APIs.

That's my first thought, since I don't see any OpenGL setup code in your snippet. I never tried running it on Android, or an any other GLES device though.

kblaschke commented 1 month ago

I have seen similar errors when calling projectm_create() without having an OpenGL context associated with the calling thread.

That would also be my guess. Either no GL context at all (or none active), or not the correct GLES version used (projectM needs GLES 3 to work, with GLES 3.1 features enabled).

The reason for the abort and assertion regarding m_activePreset when rendering a frame then happens because projectM couldn't load the "idle" preset on startup due to the OpenGL issue.

We're working on better error handling and reporting in version 4.2, so when that one's done, you should be able to get proper error messages from the library if something fails, helping to find and fix the issue.

So check that the proper context is there. I'm not an Android dev, so this is something I found that may work: http://www.anandmuralidhar.com/blog/android/gles-context/ You can check if GLES 3.1 features are available like this I guess:

int[] vers = new int[2];
GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, vers, 0);
GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, vers, 1);
if (vers[0] > 3 || (vers[0] == 3 && vers[1] >= 1)) {
    // We have at least ES 3.1.
}

Then make sure that both creating projectM and the rendering call happen in the same thread, ensuring the GL context being active.

Please give feedback if that approach worked. We'll then add proper documentation for Android, so others won't run into the same trap.

Kyborg2011 commented 1 month ago

I have seen similar errors when calling projectm_create() without having an OpenGL context associated with the calling thread.

That would also be my guess. Either no GL context at all (or none active), or not the correct GLES version used (projectM needs GLES 3 to work, with GLES 3.1 features enabled).

The reason for the abort and assertion regarding m_activePreset when rendering a frame then happens because projectM couldn't load the "idle" preset on startup due to the OpenGL issue.

We're working on better error handling and reporting in version 4.2, so when that one's done, you should be able to get proper error messages from the library if something fails, helping to find and fix the issue.

So check that the proper context is there. I'm not an Android dev, so this is something I found that may work: http://www.anandmuralidhar.com/blog/android/gles-context/ You can check if GLES 3.1 features are available like this I guess:

int[] vers = new int[2];
GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, vers, 0);
GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, vers, 1);
if (vers[0] > 3 || (vers[0] == 3 && vers[1] >= 1)) {
    // We have at least ES 3.1.
}

Then make sure that both creating projectM and the rendering call happen in the same thread, ensuring the GL context being active.

Please give feedback if that approach worked. We'll then add proper documentation for Android, so others won't run into the same trap.

No, guys, problem not in another thread... That's my code of a GLSurfaceView.Renderer:

class MilkdropVisualizationRenderer(
    private val playbackManager: PlaybackManager,
    val assetPath: String
) : GLSurfaceView.Renderer {
    override fun onSurfaceCreated(gl: GL10?, config: javax.microedition.khronos.egl.EGLConfig?) {
        Timber.tag("projectM").d("RenderWrapper onSurfaceCreated")

        val vers = IntArray(2)
        gl?.glGetIntegerv(GLES30.GL_MAJOR_VERSION, vers, 0)
        gl?.glGetIntegerv(GLES30.GL_MINOR_VERSION, vers, 1)
        Timber.d("GLES version: ${vers[0]}.${vers[1]}")

        val width: Int = Resources.getSystem().getDisplayMetrics().widthPixels
        val height: Int = Resources.getSystem().getDisplayMetrics().heightPixels
        playbackManager.initMilkdropVisualizer(assetPath)
        playbackManager.milkdropVisualizerSetWindow(width, height)
    }

    override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) {
        Timber.tag("projectM").d("RenderWrapper onSurfaceChanged")
        GLES32.glViewport(0, 0, width, height)
        playbackManager.milkdropVisualizerSetWindow(width, height)
    }

    override fun onDrawFrame(gl: GL10?) {
        Timber.tag("projectM").d("RenderWrapper RenderFrame")
        playbackManager.milkdropVisualizerRenderFrame()
    }
}

The thread is 100% the same! That's my logcat:

2024-07-13 00:30:35.449 15775-16420 projectM                xyz.luceolab.cadenza                 D  RenderWrapper onSurfaceCreated
2024-07-13 00:30:35.452 15775-16420 MilkdropVi...onRenderer xyz.luceolab.cadenza                 D  GLES version: 3.2
2024-07-13 00:30:35.454 15775-16420 projectM                xyz.luceolab.cadenza                 D  RenderWrapper onSurfaceChanged

You can see that GLES version is 3.2! And the thread is 16420. Than logcat of a projectM error:

2024-07-13 00:30:35.974 15775-16420 libc                    xyz.luceolab.cadenza                 A  /Users/aroslavivanov/.ssh/dev/cadenza-music-player/gen-libs/projectm/src/libprojectM/ProjectM.cpp:215: void libprojectM::ProjectM::LoadIdlePreset(): assertion "m_activePreset" failed
2024-07-13 00:30:36.110 15775-16420 libc                    xyz.luceolab.cadenza                 A  Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 16420 (GLThread 189), pid 15775 (uceolab.cadenza)

You can see that thread the same: 16420 (GLThread 189). And error unfortunately the same!

So, bug is somewhere else. I am not a pro in OpenGL ES (honestly , first time working close with it), so in any case I need a help from community...

Kyborg2011 commented 1 month ago

By the way, even if I call "get gles version" from c++ code (the same function where I trying projectm_create) I have gotten the right result:

GLES version: OpenGL ES 3.2 v1.r38p1-01bet0-mbs2v41_0.8320a750c7c9e2666df3500d139b434f

The c++ code:

const char* version_str = (const char*)glGetString(GL_VERSION);
LOGD("GLES version: %s", version_str);

So, as GLES context working in my custom c++ code, so the problem 100% in projectM by itself!

Kyborg2011 commented 1 month ago

I have tested current problem on emulator with API 35, arm64-8a. On emulator a projectm instance was created successfully, but there is an error on opengl_render_frame:

GLES version: 3.0
2024-07-13 15:44:54.796  6820-7163  cadenza                 xyz.luceolab.cadenza                 D  GLES version: OpenGL ES 3.0 (4.1 Metal - 88.1)
2024-07-13 15:44:54.845  6820-6902  EGL_emulation           xyz.luceolab.cadenza                 D  app_time_stats: avg=252.90ms min=11.20ms max=8008.60ms count=35
2024-07-13 15:44:54.850  6820-6820  ImageReader_JNI         xyz.luceolab.cadenza                 W  Unable to acquire a buffer item, very likely client tried to acquire more than maxImages buffers
2024-07-13 15:44:54.928  6820-6902  EGL_emulation           xyz.luceolab.cadenza                 D  app_time_stats: avg=9.40ms min=2.27ms max=68.82ms count=50
2024-07-13 15:44:54.976  6820-7163  cadenza                 xyz.luceolab.cadenza                 D  projectM init success!
2024-07-13 15:44:54.977  6820-7163  projectM                xyz.luceolab.cadenza                 D  RenderWrapper onSurfaceChanged
2024-07-13 15:44:54.977  6820-7163  projectM                xyz.luceolab.cadenza                 D  RenderWrapper RenderFrame
2024-07-13 15:44:54.977  6820-7163  cadenza                 xyz.luceolab.cadenza                 D  Before Render Frame!
2024-07-13 15:44:55.003  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.091  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.152  6820-7163  libc                    xyz.luceolab.cadenza                 A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1398 in tid 7163 (GLThread 328), pid 6820 (uceolab.cadenza)
2024-07-13 15:44:55.205  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.275  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.363  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.455  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.545  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.636  6820-6845  cadenza                 xyz.luceolab.cadenza                 D  projectM: samples added!
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A  Cmdline: xyz.luceolab.cadenza
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A  pid: 6820, tid: 7163, name: GLThread 328  >>> xyz.luceolab.cadenza <<<
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #00 pc 000000000019b2ec  /data/app/~~Ql2xH6Ji05WAr2OIy3jwCQ==/xyz.luceolab.cadenza-rkdLyXm5lyrPjqgnmkU9aw==/base.apk!libprojectM-4d.so (offset 0xd08000) (BuildId: 9974e8fc4ac06827f835761ca33d5d96f9b14b0e)
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #01 pc 0000000000196bac  /data/app/~~Ql2xH6Ji05WAr2OIy3jwCQ==/xyz.luceolab.cadenza-rkdLyXm5lyrPjqgnmkU9aw==/base.apk!libprojectM-4d.so (offset 0xd08000) (BuildId: 9974e8fc4ac06827f835761ca33d5d96f9b14b0e)
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #02 pc 000000000019a5b0  /data/app/~~Ql2xH6Ji05WAr2OIy3jwCQ==/xyz.luceolab.cadenza-rkdLyXm5lyrPjqgnmkU9aw==/base.apk!libprojectM-4d.so (offset 0xd08000) (projectm_opengl_render_frame+36) (BuildId: 9974e8fc4ac06827f835761ca33d5d96f9b14b0e)
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #03 pc 00000000001b1c30  /data/app/~~Ql2xH6Ji05WAr2OIy3jwCQ==/xyz.luceolab.cadenza-rkdLyXm5lyrPjqgnmkU9aw==/base.apk!libaudio_engine.so (offset 0x3b68000) (cadenza::MilkDropVisualizer::RenderFrame()+24) (BuildId: e8f212d4af31a508aaff627a36f9171231416e58)
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #04 pc 00000000001c35b0  /data/app/~~Ql2xH6Ji05WAr2OIy3jwCQ==/xyz.luceolab.cadenza-rkdLyXm5lyrPjqgnmkU9aw==/base.apk!libaudio_engine.so (offset 0x3b68000) (cadenza::SoxPlayerApp::MilkDropVisualizerRenderFrame()+104) (BuildId: e8f212d4af31a508aaff627a36f9171231416e58)
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #05 pc 00000000001d1280  /data/app/~~Ql2xH6Ji05WAr2OIy3jwCQ==/xyz.luceolab.cadenza-rkdLyXm5lyrPjqgnmkU9aw==/base.apk!libaudio_engine.so (offset 0x3b68000) (MilkDropVisualizerRenderFrame(_JNIEnv*, _jobject*)+28) (BuildId: e8f212d4af31a508aaff627a36f9171231416e58)
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #11 pc 000000000000ce64  <anonymous:73d68e6000> (xyz.luceolab.cadenza.player.PlaybackManager.milkdropVisualizerRenderFrame+0)
2024-07-13 15:44:55.652  7172-7172  DEBUG                                                        A        #16 pc 00000000000079d0  <anonymous:73d69f9000> (xyz.luceolab.cadenza.ui.components.playback.visualisation.Milk
rullinoiz commented 1 month ago

So I managed to get version 4.0.0 compiled and running on android after tweaking a few files, solving #713, and setting my own GLM include paths. Switching over to version 4.1.0, I'm now having this exact same issue. I'm not sure what changed, but it had to have happened between these two versions

https://github.com/rullinoiz/projectm/tree/v4.0.0-android here's the modified 4.0.0 branch that I managed to compile

Kyborg2011 commented 1 month ago

So I managed to get version 4.0.0 compiled and running on android after tweaking a few files, solving #713, and setting my own GLM include paths. Switching over to version 4.1.0, I'm now having this exact same issue. I'm not sure what changed, but it had to have happened between these two versions

https://github.com/rullinoiz/projectm/tree/v4.0.0-android here's the modified 4.0.0 branch that I managed to compile

Oh, it's very cool! Good news! Can you tell me how have you built it? Through cmake as usual? My bash script is good for it? (in description of an issue I have noted it)

kblaschke commented 1 month ago

In your crash dump here there is a segmentation fault in the C library. To identify where this happens, a proper stack trace (e.g. using a debug build of libprojectM) would be super helpful to see where exactly the crash happens.

Since I'm not an Android dev, and don't actually know how to put together a working project, I can't do much more than guessing here. So there are a few things to check:

  1. Make sure the projectM instance is created in the same thread and GL context as the render frame call is run in.
  2. Make sure projectm_create() did not return a NULL pointer, e.g. check if the return value is non-zero.
  3. The OpenGL context should be at least of profile ES 3.1 (3.2 as posted above looks good though) and is properly set up when creating the projectM instance, as projectM will allocate some GL buffers/textures and load the idle preset immediately.
  4. Not sure if Android's GL implementation supports floating-point pixel formats for textures by default. E.g. with WebGL, one has to enable an extension. You may need to load/enable and check the EXT_color_buffer_half_float extension on GLES contexts lower than 3.2.
  5. As noted above, build projectM in debug configuration for testing to get proper stack traces.

If someone can provide a simple repository with a project which I can open up in Android Studio, then just build and run it in the device emulator, I can try to find out what's going on.

rullinoiz commented 1 month ago

So I managed to get version 4.0.0 compiled and running on android after tweaking a few files, solving #713, and setting my own GLM include paths. Switching over to version 4.1.0, I'm now having this exact same issue. I'm not sure what changed, but it had to have happened between these two versions

https://github.com/rullinoiz/projectm/tree/v4.0.0-android here's the modified 4.0.0 branch that I managed to compile

Oh, it's very cool! Good news! Can you tell me how have you built it? Through cmake as usual? My bash script is good for it? (in description of an issue I have noted it)

Yeah, I did it through CMake and add_subdirectory in the CMakeLists file to include it. You'll have to set ENABLE_GLES and ENABLE_SYSTEM_GLM to ON and set GLM_INCLUDE_DIR to the vendor/glm folder at the root of the repository and GLM_INCLUDE_FILE to the CMakeLists.txt file inside of that same folder

kblaschke commented 1 month ago

Yeah, I did it through CMake and add_subdirectory in the CMakeLists file to include it.

Note that the CMake project is currently not made to be used in that way, as it'll create different issues regarding include directories etc.

Either use it via CMake's add_external_project() command or just build it with the Android NDK separately, install it somewhere and then use the standard find_package() way to use it in your project.

Kyborg2011 commented 1 month ago

In your crash dump here there is a segmentation fault in the C library. To identify where this happens, a proper stack trace (e.g. using a debug build of libprojectM) would be super helpful to see where exactly the crash happens.

Since I'm not an Android dev, and don't actually know how to put together a working project, I can't do much more than guessing here. So there are a few things to check:

  1. Make sure the projectM instance is created in the same thread and GL context as the render frame call is run in.
  2. Make sure projectm_create() did not return a NULL pointer, e.g. check if the return value is non-zero.
  3. The OpenGL context should be at least of profile ES 3.1 (3.2 as posted above looks good though) and is properly set up when creating the projectM instance, as projectM will allocate some GL buffers/textures and load the idle preset immediately.
  4. Not sure if Android's GL implementation supports floating-point pixel formats for textures by default. E.g. with WebGL, one has to enable an extension. You may need to load/enable and check the EXT_color_buffer_half_float extension on GLES contexts lower than 3.2.
  5. As noted above, build projectM in debug configuration for testing to get proper stack traces.

If someone can provide a simple repository with a project which I can open up in Android Studio, then just build and run it in the device emulator, I can try to find out what's going on.

About a test repo: I have made it! You can look here: https://github.com/Kyborg2011/projectm-debug There is a simple README.md, but in general everything must be obvious... Running this repo on my Samsung Galaxy S20 Ultra I have gotten the same error:

/Users/aroslavivanov/.ssh/dev/projectm-debug/gen-libs/projectm/src/libprojectM/ProjectM.cpp:215: void libprojectM::ProjectM::LoadIdlePreset(): assertion "m_activePreset" failed
Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 8684 (GLThread 1296), pid 8549 (.projectm_debug)
Cmdline: com.example.projectm_debug
pid: 8549, tid: 8684, name: GLThread 1296  >>> com.example.projectm_debug <<<
      #02 pc 00000000001ff3c0  /data/app/~~NQBdwvbP3LS5AKFqxxSMgg==/com.example.projectm_debug-JiaTGZSxAqO4EUQtp8c2Qg==/base.apk!libprojectM-4d.so (BuildId: dd6284f08a1dadb94b7633281ca79c481f476fa6)
      #03 pc 00000000001fe1dc  /data/app/~~NQBdwvbP3LS5AKFqxxSMgg==/com.example.projectm_debug-JiaTGZSxAqO4EUQtp8c2Qg==/base.apk!libprojectM-4d.so (BuildId: dd6284f08a1dadb94b7633281ca79c481f476fa6)
      #04 pc 00000000001fdbf8  /data/app/~~NQBdwvbP3LS5AKFqxxSMgg==/com.example.projectm_debug-JiaTGZSxAqO4EUQtp8c2Qg==/base.apk!libprojectM-4d.so (BuildId: dd6284f08a1dadb94b7633281ca79c481f476fa6)
      #05 pc 00000000002020a4  /data/app/~~NQBdwvbP3LS5AKFqxxSMgg==/com.example.projectm_debug-JiaTGZSxAqO4EUQtp8c2Qg==/base.apk!libprojectM-4d.so (BuildId: dd6284f08a1dadb94b7633281ca79c481f476fa6)
      #06 pc 0000000000202010  /data/app/~~NQBdwvbP3LS5AKFqxxSMgg==/com.example.projectm_debug-JiaTGZSxAqO4EUQtp8c2Qg==/base.apk!libprojectM-4d.so (projectm_create+48) (BuildId: dd6284f08a1dadb94b7633281ca79c481f476fa6)
      #07 pc 000000000000090c  /data/app/~~NQBdwvbP3LS5AKFqxxSMgg==/com.example.projectm_debug-JiaTGZSxAqO4EUQtp8c2Qg==/base.apk!libprojectm_debug.so (Java_com_example_projectm_1debug_GLESLib_init+20) (BuildId: 7d2314018c77de748bd1978ab9c5b5e5744c5c41)
      #13 pc 0000000000000470  /data/data/com.example.projectm_debug/code_cache/.overlay/base.apk/classes3.dex (com.example.projectm_debug.GLESView$MyRenderer.onSurfaceCreated+0)
kblaschke commented 1 month ago

The app and projectM run fine for me in Android Studio using the Pixel 6 emulator: projectM in Android emulator

The rendering area doesn't fill the whole screen and seems to have a wrong aspect ratio, but I guess this is due to some layout issue in the demo app.

Edit: Same goes for my physical smartphone (a OnePlus 7 Pro): projectM on OnePlus phone

Kyborg2011 commented 1 month ago

The app and projectM run fine for me in Android Studio using the Pixel 6 emulator: projectM in Android emulator

The rendering area doesn't fill the whole screen and seems to have a wrong aspect ratio, but I guess this is due to some layout issue in the demo app.

Edit: Same goes for my physical smartphone (a OnePlus 7 Pro): projectM on OnePlus phone

Hm... Strange... Without any changes in code? And can you tell what version of Android do you tried?

kblaschke commented 1 month ago

Just checked out the project, Android Studio updated the Gradle project to 8.5.1 (from 8.5.0), but that's it, so not a huge change. Just hit build, then ran it in the emulator, and after that on my phone as well. My phone has Android 12 on it, the Pixel 6 emulated device as well.

Kyborg2011 commented 1 month ago

Just checked out the project, Android Studio updated the Gradle project to 8.5.1 (from 8.5.0), but that's it, so not a huge change. Just hit build, then ran it in the emulator, and after that on my phone as well. My phone has Android 12 on it, the Pixel 6 emulated device as well.

Okay, thank you very much! Its a very strange problem, because on my s20 ultra with Android 13 - the same project just crashed and did not launch in general... I will try make deeper debugging on weekends!

P.S.: Btw, can you tell me a GLES version on your OnePlus device? Is it 3.0/3.1 or 3.2 as on my device?

Kyborg2011 commented 1 month ago

I have found an old device (Huawei Y6 2018) with Android 8 and made a test on it - and indeed it works just fine!

So, current problem is something device-specific. As I understand it breaks by some reason on Samsung S20 and on some other devices (I have found another issue with a bug very close to current on some Pixel devices).

Very strange problem indeed...

UPD: On another phone with Android 13 (Vivo Y6) - the same problem - debug app just crashed. Maybe current bug is related to Android version as an option…

Kyborg2011 commented 1 month ago

I have found a problem and fixed it. It was here: PerPixelMesh on lines 27-28. I am not a specialist in OpenGL, so using trial and error method I have concluded that a problem was in a name of two variables. It is strange, but why it is so I do not know. The fact is: a debug app without that changes showed on Galaxy S20 Ultra and on another Android 13 device that I have only a black window (with release build) or simply crashed (with debug build). And after such changes it working as it must.

My fork with solution is here: https://github.com/Kyborg2011/projectm

And in general I have created a pull request, so, please, watch for it and make your review!

kblaschke commented 1 month ago

Good catch. OpenGL ES actually has a distance() function, which no other GL standard does, so the uniform distance seems to cause a shader compilation error with some GL drivers, but not all.

I've created two PRs with your commit, one for master and one for our 4.1 release line, as we should put this out ASAP in the 4.1.2 release, which contains another GL error fix as well.

Kyborg2011 commented 1 month ago

Okay! Thank you, then I have started understand this problem! Glad, that my little contribution was meaningful!

Good luck with development of a projectM in future! And I will help if I can (as in current issue), too.