Fix error where the app would sometimes crash due to app being NULL

This commit is contained in:
Curi0 2017-09-28 13:11:57 +05:30
parent 7848a3c72c
commit 672fed88b7
2 changed files with 9 additions and 7 deletions

View File

@ -5202,4 +5202,4 @@ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window
#endif /* _glfw3_h_ */ #endif /* _glfw3_h_ */
extern void glfwMain(); extern int main();

View File

@ -37,7 +37,7 @@ void handle_cmd(struct android_app* _app, int32_t cmd) {
// The window is being shown, get it ready. // The window is being shown, get it ready.
app = _app; app = _app;
__android_log_print(ANDROID_LOG_INFO, "GLFW", __android_log_print(ANDROID_LOG_INFO, "GLFW",
"Window initialized", cmd); "Window initialized");
default: default:
__android_log_print(ANDROID_LOG_INFO, "GLFW", __android_log_print(ANDROID_LOG_INFO, "GLFW",
"event not handled: %d", cmd); "event not handled: %d", cmd);
@ -47,8 +47,7 @@ void handle_cmd(struct android_app* _app, int32_t cmd) {
// Android Entry Point // Android Entry Point
void android_main(struct android_app *app) { void android_main(struct android_app *app) {
app->onAppCmd = handle_cmd; app->onAppCmd = handle_cmd;
pthread_t my_thread; pthread_t t;pthread_create(&t, NULL, &main, NULL); // Call the main entry point
pthread_create(&my_thread, NULL, &glfwMain, NULL);
while (1) { while (1) {
int ident; int ident;
@ -79,6 +78,9 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
const _GLFWctxconfig* ctxconfig, const _GLFWctxconfig* ctxconfig,
const _GLFWfbconfig* fbconfig) const _GLFWfbconfig* fbconfig)
{ {
while (app == NULL); // Wait for the app to be initialized or the app will crash occasionally
window->android.app = app;
if (ctxconfig->client != GLFW_NO_API) if (ctxconfig->client != GLFW_NO_API)
{ {
if (ctxconfig->source == GLFW_EGL_CONTEXT_API) if (ctxconfig->source == GLFW_EGL_CONTEXT_API)
@ -337,7 +339,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
memset(&sci, 0, sizeof(sci)); memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR;
sci.window = app->window; sci.window = window->android.app->window;
err = vkCreateAndroidSurfaceKHR(instance, &sci, allocator, surface); err = vkCreateAndroidSurfaceKHR(instance, &sci, allocator, surface);
if (err) if (err)
@ -356,7 +358,7 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
GLFWAPI struct android_app * glfwGetAndroidApp(GLFWwindow* handle) GLFWAPI struct android_app * glfwGetAndroidApp(GLFWwindow* handle)
{ {
_GLFWwindow* window = (_GLFWwindow*) handle; _GLFWwindow* window = (_GLFWwindow*)handle;
_GLFW_REQUIRE_INIT_OR_RETURN(NULL); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return app; return window->android.app;
} }