Skip to content

Commit 599f7b2

Browse files
sienaiwunslaren
authored andcommitted
Fix crash caused by ggml_backend_load_all when launching on Android Activity (ggml-org#10812)
* 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 <[email protected]>
1 parent 61cf1ed commit 599f7b2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ggml/src/ggml-backend-reg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,
473473
if (!fs::exists(search_path)) {
474474
continue;
475475
}
476-
for (const auto & entry : fs::directory_iterator(search_path)) {
476+
fs::directory_iterator dir_it(search_path, fs::directory_options::skip_permission_denied);
477+
for (const auto & entry : dir_it) {
477478
if (entry.is_regular_file()) {
478479
std::string filename = entry.path().filename().string();
479480
std::string ext = entry.path().extension().string();

0 commit comments

Comments
 (0)