From 1de34141d3e464f3633da13c307b9b557d0cdb81 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 1 Mar 2026 21:39:10 +0200 Subject: [PATCH 1/3] Fix Android native build. I hope we aren't using any more globally initialized classes, because it seems they're broken! (reset to 0 because the app loads nbcraft TWICE!! before android_app_entry gets a chance to run) --- platforms/android/AppPlatform_android.cpp | 5 +++++ platforms/android/AppPlatform_android.hpp | 1 + platforms/android/android_native_app_glue.c | 5 +++-- platforms/android/main.cpp | 21 +++++++++++-------- platforms/android/project/app/build.gradle | 6 +++--- .../project/app/src/main/AndroidManifest.xml | 2 +- .../app/src/main/res/values/strings.xml | 2 +- platforms/android/project/settings.gradle | 2 +- platforms/audio/opensl/CustomSoundSystem.hpp | 1 + platforms/audio/opensl/SoundSystemOSL.cpp | 5 +++++ 10 files changed, 33 insertions(+), 17 deletions(-) diff --git a/platforms/android/AppPlatform_android.cpp b/platforms/android/AppPlatform_android.cpp index ceb1f9872..7e23bd8a8 100644 --- a/platforms/android/AppPlatform_android.cpp +++ b/platforms/android/AppPlatform_android.cpp @@ -280,3 +280,8 @@ AssetFile AppPlatform_android::readAssetFile(const std::string& str, bool quiet) AAsset_close(asset); return AssetFile(ssize_t(cnt), buffer); } + +std::string AppPlatform_android::getAssetPath(const std::string& path) const +{ + return path; +} diff --git a/platforms/android/AppPlatform_android.hpp b/platforms/android/AppPlatform_android.hpp index ce7f219a4..832490e67 100644 --- a/platforms/android/AppPlatform_android.hpp +++ b/platforms/android/AppPlatform_android.hpp @@ -55,6 +55,7 @@ class AppPlatform_android : public AppPlatform void setExternalStoragePath(const std::string& path); AssetFile readAssetFile(const std::string&, bool) const override; + std::string getAssetPath(const std::string&) const override; private: void changeKeyboardVisibility(bool bShown); diff --git a/platforms/android/android_native_app_glue.c b/platforms/android/android_native_app_glue.c index a2341c51b..d999e630b 100644 --- a/platforms/android/android_native_app_glue.c +++ b/platforms/android/android_native_app_glue.c @@ -26,8 +26,8 @@ #include "android_native_app_glue.h" #include -#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "ReMinecraftPE", __VA_ARGS__)) -#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "ReMinecraftPE", __VA_ARGS__)) +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "NBCraft", __VA_ARGS__)) +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "NBCraft", __VA_ARGS__)) /* For debug builds, always enable the debug traces in this library */ #ifndef NDEBUG @@ -202,6 +202,7 @@ static void process_cmd(struct android_app* app, struct android_poll_source* sou } static void* android_app_entry(void* param) { + LOGI("hi there from android_app_entry"); struct android_app* android_app = (struct android_app*)param; android_app->config = AConfiguration_new(); diff --git a/platforms/android/main.cpp b/platforms/android/main.cpp index 0108c7c04..03c852a97 100644 --- a/platforms/android/main.cpp +++ b/platforms/android/main.cpp @@ -25,8 +25,10 @@ #include "client/player/input/Mouse.hpp" #include "client/player/input/Multitouch.hpp" - -AppPlatform_android g_AppPlatform; +// TODO FIX: For some reason, after this constructor is initialized, AppPlatform::m_singleton +// gets reset to 0, seemingly because for some reason, libnbcraft.so is loaded again! Why?? +//AppPlatform_android g_AppPlatform; +AppPlatform_android* g_pAppPlatform; bool g_LButtonDown, g_RButtonDown; int g_MousePosX, g_MousePosY; @@ -332,17 +334,17 @@ static void initWindow(struct engine* engine, struct android_app* app) eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w); eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h); - g_AppPlatform.initConsts(); - g_AppPlatform.setScreenSize(w, h); - g_AppPlatform.initAndroidApp(app); + g_pAppPlatform->initConsts(); + g_pAppPlatform->setScreenSize(w, h); + g_pAppPlatform->initAndroidApp(app); engine->ninecraftApp->width = w; engine->ninecraftApp->height = h; if (!engine->initted) { - g_AppPlatform.m_externalStorageDir = getExternalStorageDir(engine); - g_AppPlatform.setExternalStoragePath(g_AppPlatform.m_externalStorageDir); + g_pAppPlatform->m_externalStorageDir = getExternalStorageDir(engine); + g_pAppPlatform->setExternalStoragePath(g_pAppPlatform->m_externalStorageDir); engine->ninecraftApp->init(); } else @@ -398,8 +400,9 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { } void android_main(struct android_app* state) { + g_pAppPlatform = new AppPlatform_android(); + struct engine engine; - memset(&engine, 0, sizeof(engine)); state->userData = &engine; state->onAppCmd = engine_handle_cmd; @@ -407,7 +410,7 @@ void android_main(struct android_app* state) { engine.androidApp = state; engine.ninecraftApp = new NinecraftApp; - engine.ninecraftApp->m_pPlatform = &g_AppPlatform; + engine.ninecraftApp->m_pPlatform = g_pAppPlatform; while (1) { diff --git a/platforms/android/project/app/build.gradle b/platforms/android/project/app/build.gradle index d5f75a6f6..3f294b856 100644 --- a/platforms/android/project/app/build.gradle +++ b/platforms/android/project/app/build.gradle @@ -3,7 +3,7 @@ plugins { } android { - namespace 'com.reminecraftpe' + namespace 'org.nbcraft' compileSdk 21 // Employ a hack which copies the assets folder in to the local assets folder. @@ -43,7 +43,7 @@ android { } defaultConfig { - applicationId "com.reminecraftpe" + applicationId "org.nbcraft" minSdk 16 // Don't inspect the target SDK. You'd better not intend to upload this to the Google Play Store. //noinspection ExpiredTargetSdkVersion @@ -54,7 +54,7 @@ android { // testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { - arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_static', '-DREMCPE_PLATFORM=android', '-DREMCPE_AUDIO_LIBRARY=opensl' + arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_static', '-DNBC_PLATFORM=android', '-DNBC_AUDIO_LIBRARY=opensl', '-DNBC_GFX_API=OGL' abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } } diff --git a/platforms/android/project/app/src/main/AndroidManifest.xml b/platforms/android/project/app/src/main/AndroidManifest.xml index b14d45171..e60b6394c 100644 --- a/platforms/android/project/app/src/main/AndroidManifest.xml +++ b/platforms/android/project/app/src/main/AndroidManifest.xml @@ -24,7 +24,7 @@ + android:value="nbcraft" /> diff --git a/platforms/android/project/app/src/main/res/values/strings.xml b/platforms/android/project/app/src/main/res/values/strings.xml index 27d02ca31..76e6c28c4 100644 --- a/platforms/android/project/app/src/main/res/values/strings.xml +++ b/platforms/android/project/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - ReMinecraftPE + NBCraft \ No newline at end of file diff --git a/platforms/android/project/settings.gradle b/platforms/android/project/settings.gradle index a2cd4b353..1ab966bd5 100644 --- a/platforms/android/project/settings.gradle +++ b/platforms/android/project/settings.gradle @@ -12,5 +12,5 @@ dependencyResolutionManagement { mavenCentral() } } -rootProject.name = "ReMinecraftPE" +rootProject.name = "NBCraft" include ':app' diff --git a/platforms/audio/opensl/CustomSoundSystem.hpp b/platforms/audio/opensl/CustomSoundSystem.hpp index eb3916f13..1388d0dd6 100644 --- a/platforms/audio/opensl/CustomSoundSystem.hpp +++ b/platforms/audio/opensl/CustomSoundSystem.hpp @@ -41,6 +41,7 @@ class SoundSystemOSL : public SoundSystem void destroy(); bool checkErr(SLresult res); void removeStoppedSounds(); + bool isAvailable() override; void setListenerPos(const Vec3& pos) override; void setListenerAngle(const Vec2& rot) override; void playAt(const SoundDesc& sound, const Vec3& pos, float volume, float pitch) override; diff --git a/platforms/audio/opensl/SoundSystemOSL.cpp b/platforms/audio/opensl/SoundSystemOSL.cpp index d1529b05f..c71f4661b 100644 --- a/platforms/audio/opensl/SoundSystemOSL.cpp +++ b/platforms/audio/opensl/SoundSystemOSL.cpp @@ -214,3 +214,8 @@ void SoundSystemOSL::destroy() { } + +bool SoundSystemOSL::isAvailable() override +{ + return true; +} From 0c51b54ac1dbf63a518e8c056933901280c32870 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 1 Mar 2026 21:41:38 +0200 Subject: [PATCH 2/3] Remove accidental leftover debug log --- platforms/android/android_native_app_glue.c | 1 - 1 file changed, 1 deletion(-) diff --git a/platforms/android/android_native_app_glue.c b/platforms/android/android_native_app_glue.c index d999e630b..7bc12952c 100644 --- a/platforms/android/android_native_app_glue.c +++ b/platforms/android/android_native_app_glue.c @@ -202,7 +202,6 @@ static void process_cmd(struct android_app* app, struct android_poll_source* sou } static void* android_app_entry(void* param) { - LOGI("hi there from android_app_entry"); struct android_app* android_app = (struct android_app*)param; android_app->config = AConfiguration_new(); From 7abbca494e260ed05674c8d72e819160a49250cc Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 1 Mar 2026 22:39:02 +0200 Subject: [PATCH 3/3] Revert Android main.cpp change and fix underlying issue Yeah turns out `= nullptr;` is a whole ahh static initialization with a function in .init_array instead of just clearing the value to 0 --- platforms/android/CMakeLists.txt | 8 ++++---- platforms/android/main.cpp | 20 ++++++++------------ source/client/app/AppPlatform.cpp | 4 +++- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/platforms/android/CMakeLists.txt b/platforms/android/CMakeLists.txt index 7eab1d983..731215bce 100644 --- a/platforms/android/CMakeLists.txt +++ b/platforms/android/CMakeLists.txt @@ -24,15 +24,15 @@ target_link_libraries(nbcraft stb_image) target_link_libraries(nbcraft android) # Check for the presence of some optional asset based features. -if(EXISTS "${MC_ROOT}/game/assets/gui/background/panorama_0.png") +if(EXISTS "${NBC_ROOT}/game/assets/gui/background/panorama_0.png") target_compile_definitions(nbcraft PUBLIC FEATURE_MENU_BACKGROUND) endif() -if(EXISTS "${MC_ROOT}/game/assets/environment/clouds.png") +if(EXISTS "${NBC_ROOT}/game/assets/environment/clouds.png") target_compile_definitions(nbcraft PUBLIC FEATURE_CLOUDS) endif() -if(EXISTS "${MC_ROOT}/game/assets/misc/grasscolor.png") +if(EXISTS "${NBC_ROOT}/game/assets/misc/grasscolor.png") target_compile_definitions(nbcraft PUBLIC FEATURE_GRASS_COLOR) endif() -if(EXISTS "${MC_ROOT}/game/assets/misc/foliagecolor.png") +if(EXISTS "${NBC_ROOT}/game/assets/misc/foliagecolor.png") target_compile_definitions(nbcraft PUBLIC FEATURE_FOLIAGE_COLOR) endif() diff --git a/platforms/android/main.cpp b/platforms/android/main.cpp index 03c852a97..e99776c09 100644 --- a/platforms/android/main.cpp +++ b/platforms/android/main.cpp @@ -25,10 +25,8 @@ #include "client/player/input/Mouse.hpp" #include "client/player/input/Multitouch.hpp" -// TODO FIX: For some reason, after this constructor is initialized, AppPlatform::m_singleton -// gets reset to 0, seemingly because for some reason, libnbcraft.so is loaded again! Why?? -//AppPlatform_android g_AppPlatform; -AppPlatform_android* g_pAppPlatform; + +AppPlatform_android g_AppPlatform; bool g_LButtonDown, g_RButtonDown; int g_MousePosX, g_MousePosY; @@ -334,17 +332,17 @@ static void initWindow(struct engine* engine, struct android_app* app) eglQuerySurface(engine->display, engine->surface, EGL_WIDTH, &w); eglQuerySurface(engine->display, engine->surface, EGL_HEIGHT, &h); - g_pAppPlatform->initConsts(); - g_pAppPlatform->setScreenSize(w, h); - g_pAppPlatform->initAndroidApp(app); + g_AppPlatform.initConsts(); + g_AppPlatform.setScreenSize(w, h); + g_AppPlatform.initAndroidApp(app); engine->ninecraftApp->width = w; engine->ninecraftApp->height = h; if (!engine->initted) { - g_pAppPlatform->m_externalStorageDir = getExternalStorageDir(engine); - g_pAppPlatform->setExternalStoragePath(g_pAppPlatform->m_externalStorageDir); + g_AppPlatform.m_externalStorageDir = getExternalStorageDir(engine); + g_AppPlatform.setExternalStoragePath(g_AppPlatform.m_externalStorageDir); engine->ninecraftApp->init(); } else @@ -400,8 +398,6 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { } void android_main(struct android_app* state) { - g_pAppPlatform = new AppPlatform_android(); - struct engine engine; memset(&engine, 0, sizeof(engine)); state->userData = &engine; @@ -410,7 +406,7 @@ void android_main(struct android_app* state) { engine.androidApp = state; engine.ninecraftApp = new NinecraftApp; - engine.ninecraftApp->m_pPlatform = g_pAppPlatform; + engine.ninecraftApp->m_pPlatform = &g_AppPlatform; while (1) { diff --git a/source/client/app/AppPlatform.cpp b/source/client/app/AppPlatform.cpp index ef28f0f4b..31626e691 100644 --- a/source/client/app/AppPlatform.cpp +++ b/source/client/app/AppPlatform.cpp @@ -18,7 +18,9 @@ #include "compat/LegacyCPP.hpp" #include "AppPlatformListener.hpp" -AppPlatform* AppPlatform::m_singleton = nullptr; +// NOTE: don't initialize this with `nullptr`, because some compilers think ` = nullptr;` is a +// static initialization rather than just setting to null/0. +AppPlatform* AppPlatform::m_singleton = NULL; AppPlatform* AppPlatform::singleton() {