summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/io/resource_loader.cpp30
-rw-r--r--core/os/main_loop.cpp4
-rw-r--r--core/os/os.cpp7
-rw-r--r--core/resource.cpp2
4 files changed, 33 insertions, 10 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index c01aff9144..66dc9730c5 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -202,12 +202,32 @@ RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p
else
local_path = ProjectSettings::get_singleton()->localize_path(p_path);
- if (!p_no_cache && ResourceCache::has(local_path)) {
+ if (!p_no_cache) {
+ //lock first if possible
+ if (ResourceCache::lock) {
+ ResourceCache::lock->read_lock();
+ }
- print_verbose("Loading resource: " + local_path + " (cached)");
- if (r_error)
- *r_error = OK;
- return RES(ResourceCache::get(local_path));
+ //get ptr
+ Resource **rptr = ResourceCache::resources.getptr(local_path);
+
+ if (rptr) {
+ RES res(*rptr);
+ //it is possible this resource was just freed in a thread. If so, this referencing will not work and resource is considered not cached
+ if (res.is_valid()) {
+ //referencing is fine
+ if (r_error)
+ *r_error = OK;
+ if (ResourceCache::lock) {
+ ResourceCache::lock->read_unlock();
+ }
+ print_verbose("Loading resource: " + local_path + " (cached)");
+ return res;
+ }
+ }
+ if (ResourceCache::lock) {
+ ResourceCache::lock->read_unlock();
+ }
}
bool xl_remapped = false;
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index c51801e3e2..6dba77ec9a 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -33,14 +33,14 @@
void MainLoop::_bind_methods() {
- ClassDB::bind_method(D_METHOD("input_event", "ev"), &MainLoop::input_event);
+ ClassDB::bind_method(D_METHOD("input_event", "event"), &MainLoop::input_event);
ClassDB::bind_method(D_METHOD("input_text", "text"), &MainLoop::input_text);
ClassDB::bind_method(D_METHOD("init"), &MainLoop::init);
ClassDB::bind_method(D_METHOD("iteration", "delta"), &MainLoop::iteration);
ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle);
ClassDB::bind_method(D_METHOD("finish"), &MainLoop::finish);
- BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo("_input_text", PropertyInfo(Variant::STRING, "text")));
BIND_VMETHOD(MethodInfo("_initialize"));
BIND_VMETHOD(MethodInfo("_iteration", PropertyInfo(Variant::REAL, "delta")));
diff --git a/core/os/os.cpp b/core/os/os.cpp
index e90d714450..0e6251a4fb 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -632,10 +632,13 @@ void OS::center_window() {
if (is_window_fullscreen()) return;
+ Point2 sp = get_screen_position(get_current_screen());
Size2 scr = get_screen_size(get_current_screen());
Size2 wnd = get_real_window_size();
- int x = scr.width / 2 - wnd.width / 2;
- int y = scr.height / 2 - wnd.height / 2;
+
+ int x = sp.width + (scr.width - wnd.width) / 2;
+ int y = sp.height + (scr.height - wnd.height) / 2;
+
set_window_position(Vector2(x, y));
}
diff --git a/core/resource.cpp b/core/resource.cpp
index 3078eb135a..f447f785b1 100644
--- a/core/resource.cpp
+++ b/core/resource.cpp
@@ -230,7 +230,7 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
Variant p = get(E->get().name);
if ((p.get_type() == Variant::DICTIONARY || p.get_type() == Variant::ARRAY)) {
- p = p.duplicate(p_subresources); //does not make a long of sense but should work?
+ r->set(E->get().name, p.duplicate(p_subresources));
} else if (p.get_type() == Variant::OBJECT && (p_subresources || (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE))) {
RES sr = p;