| 346 | } |
| 347 | |
| 348 | Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_error, const String &p_owner, bool p_update_from_disk) { |
| 349 | MutexLock lock(singleton->mutex); |
| 350 | |
| 351 | if (!p_owner.is_empty()) { |
| 352 | singleton->dependencies[p_owner].insert(p_path); |
| 353 | } |
| 354 | |
| 355 | Ref<GDScript> script; |
| 356 | r_error = OK; |
| 357 | if (singleton->full_gdscript_cache.has(p_path)) { |
| 358 | script = singleton->full_gdscript_cache[p_path]; |
| 359 | if (!p_update_from_disk) { |
| 360 | return script; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | if (script.is_null()) { |
| 365 | script = get_shallow_script(p_path, r_error); |
| 366 | // Only exit early if script failed to load, otherwise let reload report errors. |
| 367 | if (script.is_null()) { |
| 368 | return script; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | const String remapped_path = ResourceLoader::path_remap(p_path); |
| 373 | |
| 374 | if (p_update_from_disk) { |
| 375 | if (remapped_path.get_extension().to_lower() == "gdc") { |
| 376 | Vector<uint8_t> buffer = get_binary_tokens(remapped_path); |
| 377 | if (buffer.is_empty()) { |
| 378 | r_error = ERR_FILE_CANT_READ; |
| 379 | return script; |
| 380 | } |
| 381 | script->set_binary_tokens_source(buffer); |
| 382 | } else { |
| 383 | r_error = script->load_source_code(remapped_path); |
| 384 | if (r_error) { |
| 385 | return script; |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | // Allowing lifting the lock might cause a script to be reloaded multiple times, |
| 391 | // which, as a last resort deadlock prevention strategy, is a good tradeoff. |
| 392 | uint32_t allowance_id = WorkerThreadPool::thread_enter_unlock_allowance_zone(singleton->mutex); |
| 393 | r_error = script->reload(true); |
| 394 | WorkerThreadPool::thread_exit_unlock_allowance_zone(allowance_id); |
| 395 | if (r_error) { |
| 396 | return script; |
| 397 | } |
| 398 | |
| 399 | singleton->full_gdscript_cache[p_path] = script; |
| 400 | singleton->shallow_gdscript_cache.erase(p_path); |
| 401 | |
| 402 | return script; |
| 403 | } |
| 404 | |
| 405 | Ref<GDScript> GDScriptCache::get_cached_script(const String &p_path) { |
nothing calls this directly
no test coverage detected