@@ -21,15 +21,21 @@ public class tuxpaintActivity extends SDLActivity {
2121 // Lock object for OpenGL context synchronization
2222 private static final Object sGLLock = new Object ();
2323
24- // Native methods for EGL context synchronization to fix EGL_BAD_ACCESS errors
25- private static native void initEGLContextManager ();
26- private static native boolean lockEGLContext ();
27- private static native boolean unlockEGLContext ( );
24+ // Native methods for SDL EGL patch to fix EGL_BAD_ACCESS errors
25+ private static native void initSDLEGLPatch ();
26+ private static native boolean isSDLEGLPatchInitialized ();
27+ private static native void logCurrentThread ( String tag );
2828
2929 @ Override
3030 protected void onCreate (Bundle savedInstanceState ) {
3131 Log .v (TAG , "onCreate()" );
3232
33+ // Initialize SDL EGL patch early to prevent EGL_BAD_ACCESS errors
34+ initSDLEGLContextManager ();
35+
36+ // Log the current thread ID for debugging
37+ logCurrentThread ("onCreate" );
38+
3339 boolean requestPermissions = false ;
3440 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M && Build .VERSION .SDK_INT <= Build .VERSION_CODES .R ) {
3541 if (this .checkSelfPermission (Manifest .permission .WRITE_EXTERNAL_STORAGE ) != PackageManager .PERMISSION_GRANTED ) {
@@ -49,13 +55,21 @@ protected void onCreate(Bundle savedInstanceState) {
4955 // Synchronize OpenGL context access
5056 @ Override
5157 public void onResume () {
58+ // Using Thread.currentThread().getName() instead of deprecated getId()
59+ Log .v (TAG , "onResume() - current thread: " + Thread .currentThread ().getName ());
60+ logCurrentThread ("onResume" );
61+
5262 synchronized (sGLLock ) {
5363 super .onResume ();
5464 }
5565 }
5666
5767 @ Override
5868 public void onPause () {
69+ // Using Thread.currentThread().getName() instead of deprecated getId()
70+ Log .v (TAG , "onPause() - current thread: " + Thread .currentThread ().getName ());
71+ logCurrentThread ("onPause" );
72+
5973 synchronized (sGLLock ) {
6074 super .onPause ();
6175 }
@@ -78,15 +92,75 @@ public void onLowMemory() {
7892 super .onLowMemory ();
7993 }
8094 }
95+
96+ /**
97+ * Initializes the SDL EGL patch to prevent EGL_BAD_ACCESS errors
98+ * This method sets up native code to synchronize EGL context access
99+ */
100+ private static void initSDLEGLContextManager () {
101+ Log .i (TAG , "Initializing SDL EGL Context Manager" );
102+ // Initialize the patch in the native code
103+ initSDLEGLPatch ();
104+ Log .i (TAG , "SDL EGL Patch initialized: " + isSDLEGLPatchInitialized ());
105+ }
81106
82107 static {
83- System .loadLibrary ("c++_shared" );
84- System .loadLibrary ("tuxpaint_png" );
85- System .loadLibrary ("tuxpaint_fribidi" );
86- System .loadLibrary ("SDL2" );
87- System .loadLibrary ("tp_android_assets_fopen" );
88- System .loadLibrary ("tuxpaint_intl" );
89- System .loadLibrary ("tuxpaint_iconv" );
108+ try {
109+ System .loadLibrary ("c++_shared" );
110+ Log .i (TAG , "Loaded c++_shared" );
111+ } catch (UnsatisfiedLinkError e ) {
112+ Log .e (TAG , "Failed to load c++_shared: " + e .getMessage ());
113+ }
114+
115+ try {
116+ System .loadLibrary ("tuxpaint_png" );
117+ Log .i (TAG , "Loaded tuxpaint_png" );
118+ } catch (UnsatisfiedLinkError e ) {
119+ Log .e (TAG , "Failed to load tuxpaint_png: " + e .getMessage ());
120+ }
121+
122+ try {
123+ System .loadLibrary ("tuxpaint_fribidi" );
124+ Log .i (TAG , "Loaded tuxpaint_fribidi" );
125+ } catch (UnsatisfiedLinkError e ) {
126+ Log .e (TAG , "Failed to load tuxpaint_fribidi: " + e .getMessage ());
127+ }
128+
129+ try {
130+ System .loadLibrary ("SDL2" );
131+ Log .i (TAG , "Loaded SDL2" );
132+ } catch (UnsatisfiedLinkError e ) {
133+ Log .e (TAG , "Failed to load SDL2: " + e .getMessage ());
134+ }
135+
136+ try {
137+ System .loadLibrary ("tp_android_assets_fopen" );
138+ Log .i (TAG , "Loaded tp_android_assets_fopen" );
139+ } catch (UnsatisfiedLinkError e ) {
140+ Log .e (TAG , "Failed to load tp_android_assets_fopen: " + e .getMessage ());
141+ }
142+
143+ try {
144+ System .loadLibrary ("tuxpaint_intl" );
145+ Log .i (TAG , "Loaded tuxpaint_intl" );
146+ } catch (UnsatisfiedLinkError e ) {
147+ Log .e (TAG , "Failed to load tuxpaint_intl: " + e .getMessage ());
148+ }
149+
150+ try {
151+ System .loadLibrary ("tuxpaint_iconv" );
152+ Log .i (TAG , "Loaded tuxpaint_iconv" );
153+ } catch (UnsatisfiedLinkError e ) {
154+ Log .e (TAG , "Failed to load tuxpaint_iconv: " + e .getMessage ());
155+ }
156+
157+ // Load our SDL EGL patch native library
158+ try {
159+ System .loadLibrary ("sdl_egl_patch" );
160+ Log .i (TAG , "Loaded sdl_egl_patch" );
161+ } catch (UnsatisfiedLinkError e ) {
162+ Log .e (TAG , "Failed to load sdl_egl_patch: " + e .getMessage ());
163+ }
90164 System .loadLibrary ("tuxpaint_pixman" );
91165 System .loadLibrary ("tuxpaint_xml2" );
92166 System .loadLibrary ("tuxpaint_freetype" );
@@ -107,6 +181,6 @@ public void onLowMemory() {
107181 System .loadLibrary ("tuxpaint" );
108182
109183 // Initialize the EGL context manager to prevent EGL_BAD_ACCESS errors
110- initEGLContextManager ();
184+ initSDLEGLContextManager ();
111185 }
112186}
0 commit comments