Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
godot
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
community
godot
Commits
28eca364
Unverified
Commit
28eca364
authored
Oct 21, 2019
by
Rémi Verschelde
Committed by
GitHub
Oct 21, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #30622 from creikey/fix-path-caching
PackedScene resources are freed before they are saved
parents
119bf237
b3cb58e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
8 deletions
+40
-8
resource.cpp
core/resource.cpp
+35
-5
resource.h
core/resource.h
+5
-3
No files found.
core/resource.cpp
View file @
28eca364
...
...
@@ -365,17 +365,38 @@ bool Resource::is_translation_remapped() const {
//helps keep IDs same number when loading/saving scenes. -1 clears ID and it Returns -1 when no id stored
void
Resource
::
set_id_for_path
(
const
String
&
p_path
,
int
p_id
)
{
if
(
p_id
==
-
1
)
{
id_for_path
.
erase
(
p_path
);
if
(
ResourceCache
::
path_cache_lock
)
{
ResourceCache
::
path_cache_lock
->
write_lock
();
}
ResourceCache
::
resource_path_cache
[
p_path
].
erase
(
get_path
());
if
(
ResourceCache
::
path_cache_lock
)
{
ResourceCache
::
path_cache_lock
->
write_unlock
();
}
}
else
{
id_for_path
[
p_path
]
=
p_id
;
if
(
ResourceCache
::
path_cache_lock
)
{
ResourceCache
::
path_cache_lock
->
write_lock
();
}
ResourceCache
::
resource_path_cache
[
p_path
][
get_path
()]
=
p_id
;
if
(
ResourceCache
::
path_cache_lock
)
{
ResourceCache
::
path_cache_lock
->
write_unlock
();
}
}
}
int
Resource
::
get_id_for_path
(
const
String
&
p_path
)
const
{
if
(
id_for_path
.
has
(
p_path
))
{
return
id_for_path
[
p_path
];
if
(
ResourceCache
::
path_cache_lock
)
{
ResourceCache
::
path_cache_lock
->
read_lock
();
}
if
(
ResourceCache
::
resource_path_cache
[
p_path
].
has
(
get_path
()))
{
int
result
=
ResourceCache
::
resource_path_cache
[
p_path
][
get_path
()];
if
(
ResourceCache
::
path_cache_lock
)
{
ResourceCache
::
path_cache_lock
->
read_unlock
();
}
return
result
;
}
else
{
if
(
ResourceCache
::
path_cache_lock
)
{
ResourceCache
::
path_cache_lock
->
read_unlock
();
}
return
-
1
;
}
}
...
...
@@ -430,12 +451,21 @@ Resource::~Resource() {
}
HashMap
<
String
,
Resource
*>
ResourceCache
::
resources
;
#ifdef TOOLS_ENABLED
HashMap
<
String
,
HashMap
<
String
,
int
>
>
ResourceCache
::
resource_path_cache
;
#endif
RWLock
*
ResourceCache
::
lock
=
NULL
;
#ifdef TOOLS_ENABLED
RWLock
*
ResourceCache
::
path_cache_lock
=
NULL
;
#endif
void
ResourceCache
::
setup
()
{
lock
=
RWLock
::
create
();
#ifdef TOOLS_ENABLED
path_cache_lock
=
RWLock
::
create
();
#endif
}
void
ResourceCache
::
clear
()
{
...
...
core/resource.h
View file @
28eca364
...
...
@@ -84,9 +84,7 @@ protected:
void
_set_path
(
const
String
&
p_path
);
void
_take_over_path
(
const
String
&
p_path
);
#ifdef TOOLS_ENABLED
Map
<
String
,
int
>
id_for_path
;
#endif
public
:
static
Node
*
(
*
_get_local_scene_func
)();
//used by editor
...
...
@@ -152,6 +150,10 @@ class ResourceCache {
friend
class
ResourceLoader
;
//need the lock
static
RWLock
*
lock
;
static
HashMap
<
String
,
Resource
*>
resources
;
#ifdef TOOLS_ENABLED
static
HashMap
<
String
,
HashMap
<
String
,
int
>
>
resource_path_cache
;
// each tscn has a set of resource paths and IDs
static
RWLock
*
path_cache_lock
;
#endif // TOOLS_ENABLED
friend
void
unregister_core_types
();
static
void
clear
();
friend
void
register_core_types
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment