]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
Fix crash caused by ggml_backend_load_all when launching on Android Activity (llama...
author谢乃闻 <redacted>
Fri, 13 Dec 2024 12:56:07 +0000 (12:56 +0000)
committerGeorgi Gerganov <redacted>
Wed, 18 Dec 2024 10:52:16 +0000 (12:52 +0200)
* Fix crash caused by ggml_backend_load_all when launching on AndroidActivity.

Details:
Calling ggml_backend_load_all during initialization in the AndroidActivity project leads to a crash with the error:
terminating with uncaught exception of type std::__ndk1::__fs::filesystem::filesystem_error: filesystem error: in directory_iterator::directory_iterator(...): Permission denied [./].
This issue occurs because AndroidActivity restricts file access due to sandboxing.

Reproduction:
In the example folder, the LlamaAndroid project can reproduce the crash by calling ggml_backend_load_all first in Java_android_llama_cpp_LLamaAndroid_backend_1init.

* Update ggml/src/ggml-backend-reg.cpp

---------

Co-authored-by: Diego Devesa <redacted>
ggml/src/ggml-backend-reg.cpp

index 2e7340145eed2c0159ab91d39a77e9b456e5c4a8..b2eded903cf913b76d6385b04fbaaad0ca3438f6 100644 (file)
@@ -473,7 +473,8 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
         if (!fs::exists(search_path)) {
             continue;
         }
-        for (const auto & entry : fs::directory_iterator(search_path)) {
+        fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
+        for (const auto & entry : dir_it) {
             if (entry.is_regular_file()) {
                 std::string filename = entry.path().filename().string();
                 std::string ext = entry.path().extension().string();