Commit graph

71 commits

Author SHA1 Message Date
Rémi Verschelde
140350d767
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
2021-05-05 15:02:01 +02:00
Rémi Verschelde
a828398655
Style: Replaces uses of 0/NULL by nullptr (C++11)
Using clang-tidy's `modernize-use-nullptr`.
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
2021-05-04 16:30:23 +02:00
Rémi Verschelde
b5e1e05ef2
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks 2021-05-04 14:45:16 +02:00
Rémi Verschelde
6e600cb3f0
Style: Set clang-format Standard to c++14 2021-05-04 14:45:15 +02:00
Pedro J. Estébanez
4ddcdc031b Modernize Mutex
- Based on C++11's `mutex`
- No more need to allocate-deallocate or check for null
- No pointer anymore, just a member variable
- Platform-specific implementations no longer needed
- Simpler for `NO_THREADS`
- `BinaryMutex` added for special cases as the non-recursive version
- `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`.
- `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same.
2021-02-18 11:58:08 +01:00
Rémi Verschelde
49646383f1
Update copyright statements to 2021
Happy new year to the wonderful Godot community!

2020 has been a tough year for most of us personally, but a good year for
Godot development nonetheless with a huge amount of work done towards Godot
4.0 and great improvements backported to the long-lived 3.2 branch.

We've had close to 400 contributors to engine code this year, authoring near
7,000 commit! (And that's only for the `master` branch and for the engine code,
there's a lot more when counting docs, demos and other first-party repos.)

Here's to a great year 2021 for all Godot users 🎆

(cherry picked from commit b5334d14f7)
2021-01-13 16:17:06 +01:00
Pedro J. Estébanez
46fc451b9c Remove useless check in GDScript
The removed check was adding a protection for the case where a `Reference` has not yet got its reference count initialized and a script is called on it. That would cause the object to be released after the call. The removed code was constructing the `Variant` via the `Object` constructor so it didn't deal with the reference count and so the release was prevented.

 However, `Variant` no longer works that way so that check was useless. Now it's just illegal to run GDScript on a Reference whose reference count has not been initialized.
2020-12-01 12:35:06 +01:00
Umang Kalra
f40d46bafc
Fixes the misleading error message for call_recursive method for TreeItems
(cherry picked from commit c37f633216)
2020-11-11 15:12:02 +01:00
George Marques
798ee982ac Actually set GDScript static reference
(cherry picked from commit 0f1da72492)
2020-10-29 21:04:57 +01:00
George Marques
e360dc9a79 GDScript: Remove self static reference and create one on calls
This is needed because of the new changes to Variant. The reference
counter is increased by adding it to a Variant, which means no GDScript
will be freed (or will be double freed if manually freed somewhere).

(cherry picked from commit 4d960efafc)
2020-10-29 21:04:57 +01:00
George Marques
a8332e30f0 GDScript: Fix assert message when no custom message is set
(cherry picked from commit f29a2e2606)
2020-06-04 12:09:39 +02:00
Pedro J. Estébanez
8f90d423b9 Fix too eager GDScriptFunctionState stack cleanup
(cherry picked from commit 1f0548efd4)
2020-05-20 11:40:45 +02:00
Pedro J. Estébanez
64344e6d1d Fix object leaks caused by unfulfilled yields
Now the stack saved in a `GDScriptFunctionState` is cleared as soon as the `yield()` operation is known not to be resumed because either the script, the instance or both are deleted.

This clears problems like leaked objects by eliminating cases of circular references between `GDScriptFunctionState`s preventing them and the objects they refer to in their saved stacks from being released. As an example, this makes using `SceneTreeTimer` safer.

Furthermore, with this change it's now possible to print early warnings about `yield()`s to released script/instances, as now we know they won't be successfully resumed as the condition for that happens. However, this PR doesn't add such messages, to keep the observed behavior the same for the time being.

Also, now a backup of the function name in `GDScriptFunctionState` is used, since the script may not be valid by the time the function name is needed for the resume-after-yield error messages.
2020-05-05 17:53:47 +02:00
Pedro J. Estébanez
68cca6e619 Fix leaked objects when game ends with yields in progress 2020-04-29 14:13:36 +02:00
Rémi Verschelde
4faaf6089a Remove unused #if 0'ed code 2020-01-21 21:41:54 +01:00
ChibiDenDen
9ffa9a6bac Fix constant access in base class through subclass instance
Fixes as issue where a subclass calls a base class method that tries to access a constant from the script.
The original code went through every ower class, and for each owner, went through its inheritance tree.
This seems like the wrong order, the modified code goes to each base class, and for each base class goes through the owner tree.
This is more in line with what the parser does, as the current impelemtation allows an access that the parser does not support.
This change should not negatively affect existing code due to the way the parser works
2020-01-17 00:12:45 +02:00
George Marques
3718f8f592
GDScript: Validate object instance on is operation
Avoids crashes on debug mode. Instead it now breaks the execution and
show the error in-editor. Will still crash on release.

Also add a similar check to Marshalls to ensure the debugger doesn't
crash when trying to serialize the invalid instance.
2020-01-09 13:59:33 -03:00
Rémi Verschelde
a7f49ac9a1 Update copyright statements to 2020
Happy new year to the wonderful Godot community!

We're starting a new decade with a well-established, non-profit, free
and open source game engine, and tons of further improvements in the
pipeline from hundreds of contributors.

Godot will keep getting better, and we're looking forward to all the
games that the community will keep developing and releasing with it.
2020-01-01 11:16:22 +01:00
George Marques
475d7f0e52
GDScript: Fix type conversion in assignment with operation 2019-12-13 12:51:08 -03:00
Marcel Admiraal
83069a3c0f Remove ERR_EXPLAIN macros and the scaffolding they needed. 2019-11-11 10:57:00 +01:00
George Marques
9fcd38fc70
GDScript: validate instance before accessing it on error
Make sure the instance is valid before trying to access the script in
after an error happened. If the instance is not valid it's possible that
the script is invalid as well.

Fix #29623
2019-11-01 14:41:52 -03:00
noname1477
3659e3db9d
Fixed some obvious typos in error messages
In some errors, there were closing quotation marks but no opening (e. g. "Unable to iterate on object of type  " + 
Variant::get_type_name(container->get_type()) + "'."
2019-10-05 15:33:30 +02:00
Mitch Curtis
aa8e3e7b0f GDScript: add an optional message parameter to assert()
Before this patch, assert() only took the condition to assert on:

    assert(item_data)

Now, it can optionally take a string that will be printed upon failure:

    assert(item_data, item_name + " has no item data in ItemDatabase")

This makes it easier to immediately see what the issue is by being
able to write informative failure messages.

Thanks to @wiped1 for sharing their patch, upon which this is based.

Closes #17082
2019-09-11 15:37:11 +02:00
Bojidar Marinov
112aa6e367
Fix yield check in GDScriptFunction
Fixes #31455
2019-08-28 11:15:43 +03:00
Robin Hübner
6ab118c464 Replace 'ERR_EXPLAIN' with 'ERR_FAIL_*_MSG' in "platform", "modules/gdnative", "modules/gdscript" directories. 2019-08-09 11:13:24 +02:00
Bojidar Marinov
8336590154
Fix stack underflows when yielding twice
Also, refactor GDScriptFunctionState::_signal_callback, removing some excessive repetition.
Fixes #30269.
2019-07-17 23:48:49 +03:00
Rémi Verschelde
4d99408d12
Merge pull request #28884 from vnen/yield-resume-stack
Keep GDScript functions in stack while yielding
2019-07-01 16:35:26 +02:00
Furkan Türkal
7d8d337b2c fix some crashes 2019-07-01 14:28:29 +03:00
Rémi Verschelde
6750e1b3cd GDScript: Improve error on Object to Object invalid argument calls
Fixes #27804.
2019-06-18 11:27:43 +02:00
George Marques
9df1a2442b
Show function name in debugger stack trace
Also show script and line when the instance is gone when resuming from
yield.
2019-05-14 11:39:44 -03:00
George Marques
bdc6649b79
Keep GDScript functions in stack while yielding
This prevents GDScript functions from leaving the stack too soon when
they are resuming from yield, allowing the ones expecting it to finish
to know the caller.

Helps debugging cases when you use:
`yield(function_which_yields(), "completed")`
since now it shows the call that resumed that function.
2019-05-14 11:39:40 -03:00
Rémi Verschelde
425ec6914c
Revert "Forbid implicit type conversion in GDScript" 2019-03-04 12:25:59 +01:00
George Marques
d0b08342b8
GDScript: Forbid implicit type conversion
Since types are not present in release builds, this could cause issues
where a variable does not have the exact defined type.
2019-03-03 22:25:22 -03:00
Bojidar Marinov
f0efc7521e
Allow parameters passed to GDScript functions to be nulled
Previous version resulted in confusing (but actually right) errors about converting "from Object to Object", since CallError
does not include information about the actual types involved.
2019-03-03 15:24:06 +02:00
Bojidar Marinov
d2e43475b5
Fix wrong error messages for invalid arguments when calling functions through call
Fixes #25505
2019-01-31 17:02:18 +02:00
Rémi Verschelde
b16c309f82 Update copyright statements to 2019
Happy new year to the wonderful Godot community!
2019-01-01 12:58:10 +01:00
Rémi Verschelde
7b2ac28326
Merge pull request #23959 from RandomShaper/fix-dangling-script-fix
Fix dangling script fix
2018-11-26 10:13:00 +01:00
Pedro J. Estébanez
06b6cea62e Fix crash on signal/resume to dangling target 2018-11-25 13:16:45 +01:00
Pedro J. Estébanez
b499537e68 Revert "Fix crash on signal/resume to dangling target"
This reverts commit 54bdc1e1f6.
2018-11-24 23:46:13 +01:00
George Marques
0bc953d83b
Allow primitives to be compared to Object types with is 2018-11-17 22:41:08 -02:00
Pedro J. Estébanez
54bdc1e1f6 Fix crash on signal/resume to dangling target
Fixes #22443.
2018-10-17 20:44:47 +02:00
George Marques
6c9b1a5db2
Fix compiler warnings in GDScript module 2018-10-06 09:41:31 -03:00
Mariusz Chwalba
99d9af4fba Revert cause of #22794 2018-10-06 13:26:22 +02:00
Rémi Verschelde
95131e6f23 Fix warnings on release builds (not DEBUG_ENABLED)
Fixes the following Clang 5 warnings:
```
modules/bmp/image_loader_bmp.cpp:46:60: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
modules/bmp/image_loader_bmp.cpp:48:61: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
drivers/png/image_loader_png.cpp:231:20: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
scene/gui/graph_edit.cpp:1045:8: warning: comparison of constant 0 with expression of type 'bool' is always false [-Wtautological-constant-out-of-range-compare]

core/class_db.cpp:812:13: warning: unused variable 'check' [-Wunused-variable]
core/io/file_access_pack.cpp:172:11: warning: unused variable 'ver_rev' [-Wunused-variable]
core/math/bsp_tree.cpp:195:13: warning: unused variable 'plane' [-Wunused-variable]
core/math/bsp_tree.cpp:168:6: warning: unused variable 'plane_count' [-Wunused-variable]
modules/gdscript/gdscript_function.cpp:685:10: warning: unused variable 'ok' [-Wunused-variable]
modules/gdscript/gdscript_function.cpp:706:10: warning: unused variable 'ok' [-Wunused-variable]
modules/gdscript/gdscript_function.cpp:755:19: warning: unused variable 'var_type' [-Wunused-variable]
modules/gdscript/gdscript_function.cpp:1306:12: warning: unused variable 'err' [-Wunused-variable]

modules/gdscript/gdscript_function.cpp:158:15: warning: unused function '_get_var_type' [-Wunused-function]
modules/gdscript/gdscript_parser.cpp:750:20: warning: unused variable 'lv' [-Wunused-variable]
modules/gdscript/gdscript_parser.cpp:59:15: warning: unused function '_find_function_name' [-Wunused-function]
scene/main/node.cpp:2489:13: warning: unused function '_Node_debug_sn' [-Wunused-function]
```
2018-10-03 17:34:55 +02:00
Rémi Verschelde
bca2d3ad40 Fix invalid comparison warnings: [-Wbool-compare] and [-Wenum-compare]
Fixes the following GCC 5 warnings and actual bugs:
```
drivers/unix/net_socket_posix.cpp:562:28: warning: comparison between 'enum IP::Type' and 'enum NetSocket::Type' [-Wenum-compare]
modules/gdscript/gdscript_function.cpp:792:26: warning: comparison of constant '17' with boolean expression is always true [-Wbool-compare]
modules/gdscript/gdscript_function.cpp:792:26: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
modules/gdscript/gdscript_parser.cpp:5082:58: warning: comparison of constant '6' with boolean expression is always false [-Wbool-compare]
modules/gdscript/gdscript_parser.cpp:5082:58: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
modules/mbedtls/stream_peer_mbed_tls.cpp:286:45: warning: comparison between 'enum StreamPeerTCP::Status' and 'enum StreamPeerSSL::Status' [-Wenum-compare]
modules/mbedtls/stream_peer_mbed_tls.cpp:313:45: warning: comparison between 'enum StreamPeerTCP::Status' and 'enum StreamPeerSSL::Status' [-Wenum-compare]
```
2018-09-27 16:25:24 +02:00
Rémi Verschelde
277b24dfb7 Make core/ includes absolute, remove subfolders from include path
This allows more consistency in the manner we include core headers,
where previously there would be a mix of absolute, relative and
include path-dependent includes.
2018-09-12 09:52:22 +02:00
George Marques
4b974a36b7
GDScript: Allow is operator to test built-in types 2018-08-26 13:31:23 -03:00
George Marques
aeb0b3114d
GDScript: Fix type detection on Object typed assign
Also make typed assigns a debug-only thing, so release builds are more
lenient on errors.
2018-07-25 20:50:12 -03:00
George Marques
1ac9c0fe3a
GDScript: Allow strict conversion when assigning typed variables 2018-07-25 20:50:12 -03:00
George Marques
cd6ad5462c
GDScript: Fix returned value of get_default_argument_count() 2018-07-25 20:50:11 -03:00