Fix crash when dumping extension API in a non-writable directory

(cherry picked from commit 49400e0c1c)
This commit is contained in:
Haoyu Qiu 2023-03-08 12:30:37 +08:00 committed by Yuri Sizov
parent 5662542526
commit 2d0d07f51b
2 changed files with 2 additions and 0 deletions

View File

@ -1052,6 +1052,7 @@ void GDExtensionAPIDump::generate_extension_json_file(const String &p_path) {
String text = json->stringify(api, "\t", false) + "\n";
Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_MSG(fa.is_null(), vformat("Cannot open file '%s' for writing.", p_path));
fa->store_string(text);
}

View File

@ -27,6 +27,7 @@ class GDExtensionInterfaceDump {
public:
static void generate_gdextension_interface_file(const String &p_path) {
Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
ERR_FAIL_COND_MSG(fa.is_null(), vformat("Cannot open file '%s' for writing.", p_path));
CharString cs(gdextension_interface_dump);
fa->store_buffer((const uint8_t *)cs.ptr(), cs.length());
};