From a976e76ae644cb10002900519e2a72bd2706348f Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Thu, 8 Feb 2018 12:00:27 +0100 Subject: InitWindow: return false if no monitor found Otherwise we run into an assertion failure inside GLFW's glfwGetVideoMode. Example: http://www.cpantesters.org/cpan/report/b4ba5894-0bdb-11e8-841e-2c60b04e1d2d This is related to #456. --- src/core.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 29f9a23a..0a1c34c9 100644 --- a/src/core.c +++ b/src/core.c @@ -1733,7 +1733,13 @@ static bool InitGraphicsDevice(int width, int height) // NOTE: Getting video modes is not implemented in emscripten GLFW3 version #if defined(PLATFORM_DESKTOP) // Find monitor resolution - const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + GLFWmonitor *monitor = glfwGetPrimaryMonitor(); + if (!monitor) + { + TraceLog(LOG_WARNING, "Failed to get monitor"); + return false; + } + const GLFWvidmode *mode = glfwGetVideoMode(monitor); displayWidth = mode->width; displayHeight = mode->height; -- cgit v1.2.3 From 468309d06c7ac3e3278057cfb1cfc19b332833bf Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Fri, 9 Feb 2018 22:50:50 +0100 Subject: Early-exit InitWindow if InitGraphicsDevice fails Otherwise we may run into LoadDefaultFont and crash in rlLoadTexture Also moves InitTimer() before InitGraphicsDevice(), to allow it to be tested even if InitWindow ultimately fails. --- src/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/core.c') diff --git a/src/core.c b/src/core.c index 0a1c34c9..d6a10943 100644 --- a/src/core.c +++ b/src/core.c @@ -441,12 +441,13 @@ void InitWindow(int width, int height, void *data) uwpWindow = (EGLNativeWindowType)data; #endif + // Init hi-res timer + InitTimer(); + // Init graphics device (display device and OpenGL context) // NOTE: returns true if window and graphic device has been initialized successfully windowReady = InitGraphicsDevice(width, height); - - // Init hi-res timer - InitTimer(); + if (!windowReady) return; #if defined(SUPPORT_DEFAULT_FONT) // Load default font -- cgit v1.2.3 From d90a33b850d825c3047fd570478fc8a66f22414f Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 11 Feb 2018 01:48:53 +0100 Subject: Some reviews for Android compilation --- src/Makefile | 14 ++++++++++---- src/core.c | 4 ++-- templates/advance_game/Makefile.Android | 22 ++++------------------ 3 files changed, 16 insertions(+), 24 deletions(-) (limited to 'src/core.c') diff --git a/src/Makefile b/src/Makefile index e41a88a3..6752d9e7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -262,15 +262,20 @@ endif # -Wno-missing-braces ignore invalid warning (GCC bug 53119) # -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec # -Werror=pointer-arith catch unportable code that does direct arithmetic on void pointers -# -Werror=implicit-function-declaration catch function calls without prior declaration -CFLAGS += -O1 -Wall -std=c99 -D_DEFAULT_SOURCE -fgnu89-inline -Wno-missing-braces -Werror=pointer-arith -Werror=implicit-function-declaration +CFLAGS += -O1 -Wall -std=c99 -D_DEFAULT_SOURCE -fgnu89-inline -Wno-missing-braces -Werror=pointer-arith ifeq ($(RAYLIB_BUILD_MODE), DEBUG) CFLAGS += -g endif # Additional flags for compiler (if desired) -#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes +# -Wextra enables some extra warning flags that are not enabled by -Wall +# -Wmissing-prototypes warn if a global function is defined without a previous prototype declaration +# -Wstrict-prototypes warn if a function is declared or defined without specifying the argument types +# -Werror=implicit-function-declaration catch function calls without prior declaration +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + CFLAGS += -Werror=implicit-function-declaration +endif ifeq ($(PLATFORM),PLATFORM_WEB) # -O2 # if used, also set --memory-init-file 0 # --memory-init-file 0 # to avoid an external memory initialization code file (.mem) @@ -285,7 +290,8 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID) # Compilation functions attributes options CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC # Compiler options for the linker - CFLAGS += -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes + # -Werror=format-security + CFLAGS += -Wa,--noexecstack -Wformat -no-canonical-prefixes # Preprocessor macro definitions CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16 endif diff --git a/src/core.c b/src/core.c index d6a10943..ce017af2 100644 --- a/src/core.c +++ b/src/core.c @@ -294,11 +294,11 @@ static int renderOffsetX = 0; // Offset X from render area (must b static int renderOffsetY = 0; // Offset Y from render area (must be divided by 2) static bool fullscreen = false; // Fullscreen mode (useful only for PLATFORM_DESKTOP) static Matrix downscaleView; // Matrix to downscale view (in case screen size bigger than display size) +static bool cursorHidden = false; // Track if cursor is hidden +static bool cursorOnScreen = false; // Tracks if cursor is inside client area #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) || defined(PLATFORM_UWP) static const char *windowTitle = NULL; // Window text title... -static bool cursorHidden = false; // Track if cursor is hidden -static bool cursorOnScreen = false; // Tracks if cursor is inside client area static int screenshotCounter = 0; // Screenshots counter // Register mouse states diff --git a/templates/advance_game/Makefile.Android b/templates/advance_game/Makefile.Android index 2fda5372..f082ab23 100644 --- a/templates/advance_game/Makefile.Android +++ b/templates/advance_game/Makefile.Android @@ -53,26 +53,21 @@ APP_COMPANY_NAME ?= raylib APP_PRODUCT_NAME ?= rgame APP_VERSION_CODE ?= 1 APP_VERSION_NAME ?= 1.0 -APP_ICON_LDPI ?= $(RAYLIB_PATH)\logo\logo36x36.png -APP_ICON_MDPI ?= $(RAYLIB_PATH)\logo\logo48x48.png -APP_ICON_HDPI ?= $(RAYLIB_PATH)\logo\logo72x72.png +APP_ICON_LDPI ?= $(RAYLIB_PATH)\logo\raylib_36x36.png +APP_ICON_MDPI ?= $(RAYLIB_PATH)\logo\raylib_48x48.png +APP_ICON_HDPI ?= $(RAYLIB_PATH)\logo\raylib_72x72.png APP_SCREEN_ORIENTATION ?= landscape APP_KEYSTORE_PASS ?= raylib -# Library type used for raylib and OpenAL Soft: STATIC (.a) or SHARED (.so/.dll) +# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll) RAYLIB_LIBTYPE ?= STATIC -OPENAL_LIBTYPE ?= STATIC RAYLIB_LIB_PATH = $(RAYLIB_PATH)\release\libs\android\armeabi-v7a -OPENAL_LIB_PATH = $(RAYLIB_PATH)\release\libs\android\armeabi-v7a # Shared libs must be added to APK if required # NOTE: Generated NativeLoader.java automatically load those libraries ifeq ($(RAYLIB_LIBTYPE),SHARED) PROJECT_SHARED_LIBS = lib/armeabi-v7a/libraylib.so endif -ifeq ($(OPENAL_LIBTYPE),SHARED) - PROJECT_SHARED_LIBS += lib/armeabi-v7a/libopenal.so -endif # Compiler and archiver # NOTE: GCC is being deprectated in Android NDK r16 @@ -154,15 +149,9 @@ copy_project_required_libs: ifeq ($(RAYLIB_LIBTYPE),SHARED) copy /Y $(RAYLIB_LIB_PATH)\libraylib.so $(PROJECT_BUILD_PATH)\lib\armeabi-v7a\libraylib.so endif -ifeq ($(OPENAL_LIBTYPE),SHARED) - copy /Y $(OPENAL_LIB_PATH)\libopenal.so $(PROJECT_BUILD_PATH)\lib\armeabi-v7a\libopenal.so -endif ifeq ($(RAYLIB_LIBTYPE),STATIC) copy /Y $(RAYLIB_LIB_PATH)\libraylib.a $(PROJECT_BUILD_PATH)\lib\armeabi-v7a\libraylib.a endif -ifeq ($(OPENAL_LIBTYPE),STATIC) - copy /Y $(OPENAL_LIB_PATH)\libopenal.a $(PROJECT_BUILD_PATH)\lib\armeabi-v7a\libopenal.a -endif # Copy project required resources: strings.xml, icon.png, assets # NOTE: Required strings.xml is generated and game resources are copied to assets folder @@ -182,9 +171,6 @@ generate_loader_script: @echo. >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java @echo public class NativeLoader extends android.app.NativeActivity { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java @echo static { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java -ifeq ($(OPENAL_LIBTYPE),SHARED) - @echo System.loadLibrary("openal"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java -endif ifeq ($(RAYLIB_LIBTYPE),SHARED) @echo System.loadLibrary("raylib"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java endif -- cgit v1.2.3