Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Crash when creating mesh with fplbase_stdlib on Android #7

Closed
alculquicondor opened this issue Sep 18, 2017 · 6 comments
Closed

Crash when creating mesh with fplbase_stdlib on Android #7

alculquicondor opened this issue Sep 18, 2017 · 6 comments

Comments

@alculquicondor
Copy link
Contributor

alculquicondor commented Sep 18, 2017

I get a crash when creating a mesh from a set of vertices, precisely on glGenVertexArrays

GL_CALL(glGenVertexArrays(1, &vao));

My device supports OpenGL ES 3.2 and I think fplbase_stdlib is able to tell that at least the major version of the context is 3. However, if I force it to assume that the context is on version 2 (by commenting all these lines

if (version >= 3) {
feature_level_ = kFeatureLevel30;
AndroidInitGl3Functions();
}
), everything works and renders properly.

I'm targeting android-25, with minimum android-24 and my device is an android-25, ABI armeabi-v7a.

I feel like I'm missing calling some setup function to initialize OpenGL ES 3 functions, or maybe the proper header GLES3/gl3.h should be included on fplbase for latests Android APIs, but where?

@alculquicondor
Copy link
Contributor Author

I have the following line in my main Android.mk file:

LOCAL_LDLIBS += -ldl -lEGL -lGLESv3 -llog -lz -landroid \
  -lgvr

However, the debugger shows this:
screenshot_2017-09-18_10-10-04

I also tried adding -lGLESv3 to Android.mk files for fplbase (on FPLBASE_COMMON_LDLIBS) but the debugger still shows the same.

@aardappel
Copy link

On your API target, those functions should be natively available, i.e we do:

#if __ANDROID_API__ >= 18
#include <GLES3/gl3.h>
#else  // __ANDROID_API__ < 18
#include <GLES2/gl2.h>
#include "gl3stub.h"
#endif  // __ANDROID_API__ < 18

Only the stubs should declare them as variables that can be NULL. The init (which shouldn't run on your machine) is here:

void AndroidInitGl3Functions() {
#if __ANDROID_API__ < 18
    gl3stubInit();
#endif
}

Can you check if gl3stubInit() runs? if so, there may be something wrong with your target settings?

@alculquicondor
Copy link
Contributor Author

It doesn't run, i.e. I checked the __ANDROID_API__ variable and it is correctly set to 24. I also tried calling gl3stubInit from my application code. It returns GL_TRUE, but the segmentation fault persists.

@alculquicondor
Copy link
Contributor Author

alculquicondor commented Sep 18, 2017

Given your idea, I fixed it by removing $(NDK_ROOT)/sources/android/ndk-helper/gl3stub.c from FPLBASE_COMMON_SRC_FILES. I also have -lGLESv3 in my project's Android.mk, but that might be irrelevant. After that, the debugger no longer shows NULL for glGenVertexArrays. Although, it shows a link to libGLESv2.so for this function. But that's probably fine.

I could set a PR with this fix, but I'm not sure how to check for APP_PLATFORM < 18 (or something like that) to conditionally add gl3stub.c as source in fplbase's Android.mk.

@aardappel
Copy link

Wow, I guess this is really a linker problem then? It sees two definitions of the function, and somehow decides to make it point to the uninitialized one from gl3stub.c.

Which is weird, because I'd think they'd look like different kind of symbols to the linker, given that one is not necessarily a function pointer variable.

Anyway, as to how to fix this.. @stewartmiles, do you know how to make this conditional?

@stewartmiles
Copy link
Contributor

stewartmiles commented Sep 18, 2017

I think the easiest way to conditionally compile $(NDK_ROOT)/sources/android/ndk_helper/gl3stub.c is to add a fplbase file that includes a new file e.g fplbase/src/gl3stub_android.c and have that file switch between either compiling to nothing or including ndk_helper's stub implementation. You'll need to add $(NDK_ROOT)/sources/android to the include path when building fplbase.

In fplbase/src/gl3stub_android.c something like this:

#if defined(__ANDROID__)
#if defined(__ANDROID__API__) >= 18
#include "ndk_helper/gl3stub.c"
#endif  // defined(__ANDROID__API__) >= 18
#endif  // defined(__ANDROID__)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants