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
ff1e7cfb
Commit
ff1e7cfb
authored
May 07, 2018
by
Juan Linietsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add is_instance_valid() method to GDScript, ending more than a decade of pain.
parent
80b9edf0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
10 deletions
+18
-10
object.cpp
core/object.cpp
+0
-4
object.h
core/object.h
+0
-5
gdscript_functions.cpp
modules/gdscript/gdscript_functions.cpp
+17
-1
gdscript_functions.h
modules/gdscript/gdscript_functions.h
+1
-0
No files found.
core/object.cpp
View file @
ff1e7cfb
...
...
@@ -1919,9 +1919,7 @@ ObjectID ObjectDB::add_instance(Object *p_object) {
rw_lock
->
write_lock
();
instances
[
++
instance_counter
]
=
p_object
;
#ifdef DEBUG_ENABLED
instance_checks
[
p_object
]
=
instance_counter
;
#endif
rw_lock
->
write_unlock
();
return
instance_counter
;
...
...
@@ -1932,9 +1930,7 @@ void ObjectDB::remove_instance(Object *p_object) {
rw_lock
->
write_lock
();
instances
.
erase
(
p_object
->
get_instance_id
());
#ifdef DEBUG_ENABLED
instance_checks
.
erase
(
p_object
);
#endif
rw_lock
->
write_unlock
();
}
...
...
core/object.h
View file @
ff1e7cfb
...
...
@@ -762,15 +762,10 @@ public:
static
void
debug_objects
(
DebugFunc
p_func
);
static
int
get_object_count
();
#ifdef DEBUG_ENABLED
_FORCE_INLINE_
static
bool
instance_validate
(
Object
*
p_ptr
)
{
return
instance_checks
.
has
(
p_ptr
);
}
#else
_FORCE_INLINE_
static
bool
instance_validate
(
Object
*
p_ptr
)
{
return
true
;
}
#endif
};
//needed by macros
...
...
modules/gdscript/gdscript_functions.cpp
View file @
ff1e7cfb
...
...
@@ -122,6 +122,7 @@ const char *GDScriptFunctions::get_func_name(Function p_func) {
"print_stack"
,
"instance_from_id"
,
"len"
,
"is_instance_valid"
,
};
return
_names
[
p_func
];
...
...
@@ -1277,6 +1278,17 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
}
}
break
;
case
IS_INSTANCE_VALID
:
{
VALIDATE_ARG_COUNT
(
1
);
if
(
p_args
[
0
]
->
get_type
()
!=
Variant
::
OBJECT
)
{
r_ret
=
false
;
}
else
{
Object
*
obj
=
*
p_args
[
0
];
r_ret
=
ObjectDB
::
instance_validate
(
obj
);
}
}
break
;
case
FUNC_MAX
:
{
ERR_FAIL
();
...
...
@@ -1798,7 +1810,11 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
mi
.
return_val
.
type
=
Variant
::
INT
;
return
mi
;
}
break
;
case
IS_INSTANCE_VALID
:
{
MethodInfo
mi
(
"is_instance_valid"
,
PropertyInfo
(
Variant
::
OBJECT
,
"instance"
));
mi
.
return_val
.
type
=
Variant
::
BOOL
;
return
mi
;
}
break
;
case
FUNC_MAX
:
{
ERR_FAIL_V
(
MethodInfo
());
...
...
modules/gdscript/gdscript_functions.h
View file @
ff1e7cfb
...
...
@@ -113,6 +113,7 @@ public:
PRINT_STACK
,
INSTANCE_FROM_ID
,
LEN
,
IS_INSTANCE_VALID
,
FUNC_MAX
};
...
...
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