Skip to content

BGF: Minor fixits, part 1 - #125

Merged
natetrost merged 2 commits into
android:mainfrom
natetrost:main
Nov 10, 2026
Merged

natetrost merged 2 commits into
android:mainfrom
natetrost:main

Conversation

@natetrost

Copy link
Copy Markdown
Contributor

Fix log format args, enable printf format checking, add virtual base dtor, fix Home keycode typo

Small, low-risk fixes in base_game_framework for undefined behavior and compiler warnings:

  • VulkanAPIUtils::CheckVkResult: pass the missing message argument for the %s specifier (guarding against nullptr).
  • GraphicsAPIGLES::ParseEGLConfigs: pass the missing feature_flags_ argument for the 0x%x specifier.
  • DebugManager::Log / PlatformUtilLog::Log: add printf format attributes (via a new BGF_PRINTF_FORMAT macro, a no-op on non-GCC/Clang compilers) so -Wformat actually checks call sites. Previously these wrappers were unannotated, so the compiler could not catch the two bugs above, and -Wformat-nonliteral flagged the forwarding call to __android_log_vprint.
  • GraphicsAPIBase: add a virtual default destructor so derived GraphicsAPIGLES/GraphicsAPIVulkan objects are destroyed correctly through a base pointer (fixes -Wnon-virtual-dtor).
  • EventKeyCode: add correctly spelled kKeyCode_Home; keep kKeyCode_Gome as an alias marked [[deprecated]] for source compatibility.

Tested: agdktunnel builds with -Wall -Werror. All base_game_framework sources compile cleanly with -Wformat -Werror=format-security -Wformat-nonliteral -Wnon-virtual-dtor -Werror. Reintroducing either original log bug now fails with -Wformat-insufficient-args. Using kKeyCode_Gome emits -Wdeprecated-declarations.

…base dtor, fix Home keycode typo

Small, low-risk fixes in base_game_framework for undefined behavior and
compiler warnings:

- VulkanAPIUtils::CheckVkResult: pass the missing `message` argument for
  the `%s` specifier (guarding against nullptr).
- GraphicsAPIGLES::ParseEGLConfigs: pass the missing `feature_flags_`
  argument for the `0x%x` specifier.
- DebugManager::Log / PlatformUtilLog::Log: add printf format attributes
  (via a new BGF_PRINTF_FORMAT macro, a no-op on non-GCC/Clang compilers)
  so -Wformat actually checks call sites. Previously these wrappers were
  unannotated, so the compiler could not catch the two bugs above, and
  -Wformat-nonliteral flagged the forwarding call to
  __android_log_vprint.
- GraphicsAPIBase: add a virtual default destructor so derived
  GraphicsAPIGLES/GraphicsAPIVulkan objects are destroyed correctly
  through a base pointer (fixes -Wnon-virtual-dtor).
- EventKeyCode: add correctly spelled kKeyCode_Home; keep kKeyCode_Gome
  as an alias marked [[deprecated]] for source compatibility.

Tested: agdktunnel builds with -Wall -Werror. All base_game_framework
sources compile cleanly with -Wformat -Werror=format-security
-Wformat-nonliteral -Wnon-virtual-dtor -Werror. Reintroducing either
original log bug now fails with -Wformat-insufficient-args. Using
kKeyCode_Gome emits -Wdeprecated-declarations. Verified agdktunnel
launches and renders via Vulkan on a Pixel 10 Pro.
Fix JNI resource leaks and a Java data race in base_game_framework's
Android platform utilities:

- FilesystemManager / SystemInfoUtils: release the UTF chars obtained
  with GetStringUTFChars for the root paths and package name, via a new
  PlatformUtilAndroid::JStringToString() helper.
- Util object global ref: BaseGameFramework_Destroy() now deletes the
  global ref to the BaseGameFrameworkUtils object. Previously it was
  never deleted, so every Activity recreation leaked the old Activity.
  registerUtilObject() now passes its owning Activity, kept as a weak
  global ref. Destroy only releases a registration owned by its own
  Activity, so it can't free a newer Activity's registration (a new
  onCreate can run before the old onDestroy). No reflection is used, so
  this works under R8/ProGuard.
- Thread safety: the global ref is only accessed under a mutex. Callers
  now get their own local ref via NewUtilObjectLocalRef(), which keeps
  the object valid even if a newer Activity replaces the registration.
  This removes the cached class ref and jmethodIDs.
- Java exceptions: every native -> BaseGameFrameworkUtils call now
  checks for and clears pending exceptions. GetRootPath() and
  GetExternalStorageEmulated() null-check getExternalFilesDir() in Java
  instead of throwing a NullPointerException across JNI.
- BaseGameFrameworkUtils.retrieveFreeSpace(): the lock was held only
  while starting the background thread, not while it wrote the
  results, racing with GetEstimatedFreeSpace(). The thread now queries
  into locals and publishes all values under the lock in a finally
  block, also catching RuntimeException (getUuidForPath() can throw
  IllegalArgumentException). mFreeSpace is final, which also fixes an
  NPE if queried before Initialize().
- BaseGameFramework_Destroy() clears the JNIEnv, android_app, activity
  and native window pointers after detaching, unless a newer instance
  has already re-initialized them.

Tested on a Pixel 10 Pro with agdktunnel and CheckJNI enabled: no
CheckJNI errors. Forced 6 Activity recreations (night-mode toggles) and
checked a heap dump. Before: 7 BaseGameFrameworkUtils objects pinned by
JNI global refs. After: 1 (the current Activity's). After each
recreation, a temporary log confirmed root paths, package name, free
space, emulated storage, DPI and AEP support were correct. The app
renders normally. A new Activity registering before the old one is
destroyed was not reproduced on device.
@natetrost
natetrost merged commit 17164a2 into android:main Nov 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant