Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SIGSEGV when using SFML on Android  (Read 876 times)

0 Members and 1 Guest are viewing this topic.

thanhdz167

  • Newbie
  • *
  • Posts: 2
    • View Profile
SIGSEGV when using SFML on Android
« on: December 02, 2023, 11:19:54 am »
I've a game using SFML and they work very well on computer and now I want to port it to Android. Compiling and building are successfully and the APK has been created and I installed to my Samsung S5 Exynos running in LineageOS 14.1 (Android 7.1.2) to test. Then I have this error:

12-02 13:20:51.953 24780 24780 E libEGL  : validate_display:101 error 3001 (EGL_NOT_INITIALIZED)
12-02 13:20:51.954 24780 24780 E libEGL  : validate_display:99 error 3008 (EGL_BAD_DISPLAY)
12-02 13:20:51.954 24780 24780 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x24 in tid 24780 (ames.cyberchess)
12-02 13:20:51.955  3600  3600 W         : debuggerd: handling request: pid=24780 uid=10081 gid=10081 tid=24780
12-02 13:20:52.034 23099 24195 I Icing   : Usage reports ok 1, Failed Usage reports 0, indexed 0, rejected 0
12-02 13:20:52.057 23099 23127 I Icing   : IndexChimeraService.getServiceInterface callingPackage=com.google.android.gms componentName=null serviceId=30
12-02 13:20:52.074 24805 24805 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-02 13:20:52.074 24805 24805 F DEBUG   : LineageOS Version: 14.1-20181109-NIGHTLY-k3gxx
12-02 13:20:52.074 24805 24805 F DEBUG   : Build fingerprint: samsung/k3gxx/k3g:6.0.1/MMB29K/G900HXXU1CPF2:user/release-keys
12-02 13:20:52.074 24805 24805 F DEBUG   : Revision: 0
12-02 13:20:52.074 24805 24805 F DEBUG   : ABI: arm
12-02 13:20:52.075 24805 24805 F DEBUG   : pid: 24780, tid: 24780, name: ames.cyberchess  >>> com.cyberdaystudio.games.cyberchess <<<
12-02 13:20:52.075 24805 24805 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x24
12-02 13:20:52.075 24805 24805 F DEBUG   :     r0 00000024  r1 00000024  r2 00000000  r3 7ffffff8
12-02 13:20:52.075 24805 24805 F DEBUG   :     r4 bed4c3d8  r5 00000000  r6 00000000  r7 bed4c3d0
12-02 13:20:52.075 24805 24805 F DEBUG   :     r8 00000000  r9 b4284f38  sl b2d17950  fp bed4c6d8
12-02 13:20:52.075 24805 24805 F DEBUG   :     ip b2cf9888  sp bed4c3c8  lr b2c7f153  pc b2c7f1ae  cpsr 60070030
12-02 13:20:52.094 24805 24805 F DEBUG   :
12-02 13:20:52.094 24805 24805 F DEBUG   : backtrace:
12-02 13:20:52.094 24805 24805 F DEBUG   :     #00 pc 000451ae  /data/app/com.cyberdaystudio.games.cyberchess-1/lib/arm/libsfml-system.so (_ZN2sf5MutexD2Ev+21)
12-02 13:20:52.094 24805 24805 F DEBUG   :     #01 pc 0004514f  /data/app/com.cyberdaystudio.games.cyberchess-1/lib/arm/libsfml-system.so (_ZN2sf4LockC2ERNS_5MutexE+10)
12-02 13:20:52.094 24805 24805 F DEBUG   :     #02 pc 0000c5f5  /data/app/com.cyberdaystudio.games.cyberchess-1/lib/arm/libsfml-window.so (_ZN2sf4priv10EglContextC1EPS1_+84)
12-02 13:20:52.094 24805 24805 F DEBUG   :     #03 pc 00006eff  /data/app/com.cyberdaystudio.games.cyberchess-1/lib/arm/libsfml-window.so (_ZN2sf4priv9GlContext12initResourceEv+94)
12-02 13:20:52.094 24805 24805 F DEBUG   :     #04 pc 00008d17  /data/app/com.cyberdaystudio.games.cyberchess-1/lib/arm/libsfml-window.so (_ZN2sf10GlResourceC1Ev+6)
12-02 13:20:52.094 24805 24805 F DEBUG   :     #05 pc 00049a99  /data/app/com.cyberdaystudio.games.cyberchess-1/lib/arm/libsfml-graphics.so (_ZN2sf7TextureC2Ev+24)
12-02 13:20:52.094 24805 24805 F DEBUG   :     #06 pc 0000791c  /data/app/com.cyberdaystudio.games.cyberchess-1/lib/arm/libcyberchess.so (offset 0xa000)
12-02 13:20:52.182 23099 24195 I Icing   : Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0
12-02 13:20:52.223 23099 24195 I Icing   : Indexing com.google.android.gms-apps from com.google.android.gms
12-02 13:20:52.285 23099 24195 I Icing   : Indexing done com.google.android.gms-apps
12-02 13:20:52.289 23099 24195 I Icing   : Indexing com.google.android.gms-apps from com.google.android.gms
12-02 13:20:52.293 23099 24195 I Icing   : Indexing done com.google.android.gms-apps
12-02 13:20:52.738 24780 24780 W ames.cyberchess: type=1701 audit(0.0:1358): auid=4294967295 uid=10081 gid=10081 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 reason="memory violation" sig=11
12-02 13:20:52.747  3600  3600 W         : debuggerd: resuming target 24780
12-02 13:20:52.749  4145 24815 W ActivityManager:   Force finishing activity com.cyberdaystudio.games.cyberchess/.MainActivity

I have using the code to test and I have same error:

main.cpp:

#include "main_point.h"

void ShowWindow() {  
     sf::VideoMode screen(sf::VideoMode::getDesktopMode());    

      sf::RenderWindow window(screen, "");

      window.setFramerateLimit(30);

}

main_point.h:

// SFML Library include
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Network.hpp>

void ShowWindow();

jni.cpp:

#include <jni.h>
#include "main_point.h"

extern "C" {
    void
    Java_com_cyberdaystudio_games_cyberchess_MainActivity_showWindow(JNIEnv *env, jclass clazz) {
        ShowWindow();
    }
}

AndroidManifest.xml:

<?xml version=&#39;1.0&#39;?>
<manifest xmlns:a=&#39;http://schemas.android.com/apk/res/android&#39;
   package=&#39;com.cyberdaystudio.games.cyberchess&#39;
   a:versionCode=&#39;0&#39;
   a:versionName=&#39;0&#39;>
    <uses-sdk
       a:minSdkVersion="21"
       a:targetSdkVersion="34"/>
    <application
       a:label="CyberChess">
        <activity
           a:name=&#39;com.cyberdaystudio.games.cyberchess.MainActivity&#39;
           a:exported="true">
            <intent-filter>
                <category a:name=&#39;android.intent.category.LAUNCHER&#39;/>
                <action a:name=&#39;android.intent.action.MAIN&#39;/>
            </intent-filter>
        </activity>
    </application>
</manifest>

MainActivity.java:

package com.cyberdaystudio.games.cyberchess;

import android.app.Activity;
import java.lang.System;
import android.os.Bundle;

public class MainActivity extends Activity {
    // do nothing, successfully

    String[] libs = {
        "c++_shared",
        "sfml-activity",
        "sfml-audio",
        "sfml-graphics",
        "sfml-network",
        "sfml-system",
        "sfml-window",
        "openal",
        "cyberchess"
    };
    private static native void showWindow();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        for (String lib : libs) {
            System.loadLibrary(lib);
        }
        showWindow();
    }
}

Here is my host environment:

# ANDROID
BUILD_TOOLS=/mnt/Linux/build-tools/34.0.0
ANDROID_PLATFORM=/mnt/Linux/platforms/android-34
ANDROID_NDK=/mnt/Linux/ndk/26.1.10909125

My machine is Linux:
Linux duythanh-VivoBook-ASUSLaptop-X409FA-X409FA 6.2.0-37-generic #38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov  2 18:01:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

I have tried to read backtrace, and I guess the crash occurs when SFML library destructing
sf::Mutex
object. But I'm not have any idea to fix now.

I cloned the SFML from official git repository, checkout to branch 2.6.x and tried again. Still not work.

Is this an error of SFML 2.6.x? How can I make SFML work on Android?
« Last Edit: December 02, 2023, 11:21:30 am by thanhdz167 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SIGSEGV when using SFML on Android
« Reply #1 on: December 06, 2023, 10:18:30 am »
Any reason you're doing the whole JNI bootstrapping yourself, instead of using sfml-main?

My guess is, that something isn't being initialized as expected, see the implementation here: https://github.com/SFML/SFML/blob/2.6.x/src/SFML/Main/MainAndroid.cpp
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/