Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random scene files are starting mask/layer as 2^31 and not zero #41281

Closed
chucklepie opened this issue Aug 15, 2020 · 22 comments · Fixed by #42733
Closed

Random scene files are starting mask/layer as 2^31 and not zero #41281

chucklepie opened this issue Aug 15, 2020 · 22 comments · Fixed by #42733

Comments

@chucklepie
Copy link

chucklepie commented Aug 15, 2020

Godot version:
3.2.2 stable

OS/device including version:
linux mint 64bit

Issue description:
I was trying to find out which of my nodes had a certain layer/mask bit set (would be nice if this was a feature in the ide :) ), but when I searched my tscn files I noticed some of my nodes, instead of the collision_mask or collision_layer being 2^x they were 2^31+2^x

In these, all bits off are 2147483648 and not 0.

As screenshot below.

I appreciate not a giant bug in the scheme of things, but it might be indicative of a larger fault/overflow fault somewhere.

In addition, can somebody tell me if it's safe to edit these .tscn files and change them all to their normal numbers?

image

Steps to reproduce:
I have no idea

@chucklepie
Copy link
Author

chucklepie commented Aug 15, 2020

note, when I modify these bits, e.g. turn them all off, they never reset back to zero, as if something is holding these nodes to a particular value or setting the bit with a shift or similar maths operation rather than setting as an actual number after each bit is toggled on / off?

@chucklepie
Copy link
Author

For your reference, here is the entire file of one of these, and the physics layer definition. Nothing out of the ordinary..

[gd_scene load_steps=4 format=2]

[ext_resource path="res://assets/sprites/invisible_blocker.png" type="Texture" id=1]
[ext_resource path="res://entities/static/InvisibleBlocker.gd" type="Script" id=2]

[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 32, 27 )

[node name="InvisibleBlocker" type="StaticBody2D"]
z_index = 5
collision_layer = 2147483664
collision_mask = 8
script = ExtResource( 2 )

[node name="Sprite" type="Sprite" parent="."]
position = Vector2( 0, 6 )
scale = Vector2( 2, 1.6 )
texture = ExtResource( 1 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2( 0, 6 )
shape = SubResource( 1 )
[layer_names]

2d_physics/layer_1="player"
2d_physics/layer_2="environment"
2d_physics/layer_3="foreground"
2d_physics/layer_4="enemy"
2d_physics/layer_5="invisible_blocker01"
2d_physics/layer_6="enemy_blocked_by_tile"
2d_physics/layer_7="enemy_weapon"
2d_physics/layer_8="player_spawn_centre"

@fian46
Copy link

fian46 commented Aug 15, 2020

I can confirm this happened to me couple days ago. But i can't make minimal reproduce. Really strange bug. The work around is to make another scene similar to this and the problem is gone. It is only happens in collision mask.

@chucklepie
Copy link
Author

Not for me, it's both:

[node name="ProjectileDetection" type="Area2D" parent="."]
collision_layer = 0
collision_mask = 2147483648

@Calinou
Copy link
Member

Calinou commented Aug 15, 2020

This is probably due to a member variable being left uninitialized (which is undefined behavior in C++). See also #39695.

@chucklepie
Copy link
Author

chucklepie commented Aug 15, 2020 via email

@lawnjelly
Copy link
Member

lawnjelly commented Aug 15, 2020

That could well be correct.

2147483664 in decimal is 1000 0000 0000 0000 0000 0000 0001 0000 in binary. So the 4th bit (or 5th bit if you read from 1) is set for the layer, matching the display in the IDE, and also bit 31 (no idea why but it might be set on purpose, you'd have to check the source).

The mask is 8 which is 1000 in binary which matches the mask in the IDE.

If it is a bug having bit 31 set, it could be a wrong signed / unsigned cast or similar.

@chucklepie
Copy link
Author

chucklepie commented Aug 15, 2020 via email

@lawnjelly
Copy link
Member

I had a quick look and I can't see anything obvious that is using bit 31, so it may well be a bug. It will probably need being able to reproduce it to debug.

It seems unlikely to be directly an uninitialized value, given that in the example the correct bit was set (4), but bit 31 was set as well (that seems unlikely to occur by chance).

@chucklepie
Copy link
Author

chucklepie commented Aug 15, 2020 via email

@qarmin
Copy link
Contributor

qarmin commented Aug 15, 2020

Maybe this is caused due this errors:

modules/bullet/collision_object_bullet.cpp:307:15: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'int' changed the value to -1 (32-bit, signed)
modules/bullet/area_bullet.cpp:62:15: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'int' changed the value to -1 (32-bit, signed)
modules/bullet/collision_object_bullet.cpp:104:15: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'int' changed the value to -1 (32-bit, signed)
modules/bullet/rigid_body_bullet.cpp:248:15: runtime error: implicit conversion from type 'unsigned int' of value 4294967295 (32-bit, unsigned) to type 'int' changed the value to -1 (32-bit, signed)

@madmiraal
Copy link
Contributor

In these, all bits off are 2147483648 and not 0.

The IDE only shows 20 bits. Within code, 32 bits can be used for creating collision_layers and collision_masks. So although none of the bits are selected in the IDE, there are another 12 bits that could be set and not displayed. In this case, the 32nd bit is selected, but not displayed.

note, when I modify these bits, e.g. turn them all off, they never reset back to zero, as if something is holding these nodes to a particular value or setting the bit with a shift or similar maths operation rather than setting as an actual number after each bit is toggled on / off?

If you want to clear all the bits, use the reset button ↺ to set it to the default: 1. Then deselect the first layer/mask. If you now save the scene you will see it set to zero in the .tscn file.

@chucklepie
Copy link
Author

chucklepie commented Sep 15, 2020 via email

@Zireael07
Copy link
Contributor

The IDE only shows 20 bits. Within code, 32 bits can be used for creating collision_layers and collision_masks. So although none of the bits are selected in the IDE,

Why this discrepancy? I expect many users will be caught out by this, current bug notwithstanding.

@chucklepie
Copy link
Author

chucklepie commented Sep 15, 2020 via email

@madmiraal
Copy link
Contributor

@chucklepie Using your test project: https://gitlab.com/chucklepie-productions/games/testarea2d.git and following my instructions:

If you want to clear all the bits, use the reset button ↺ to set it to the default: 1. Then deselect the first layer/mask. If you now save the scene you will see it set to zero in the .tscn file.

The area2d.tscn goes from this:

...
[node name="Area1" type="Area2D" parent="."]
position = Vector2( 65, 196 )
collision_layer = 2147483648
collision_mask = 0

[node name="A1Collision" type="CollisionShape2D" parent="Area1"]
modulate = Color( 1, 0.717647, 0.0980392, 1 )
position = Vector2( 96, -84 )
shape = SubResource( 1 )

[node name="Area2" type="Area2D" parent="."]
position = Vector2( 228, 205 )
collision_layer = 0
collision_mask = 0

[node name="A2Collision" type="CollisionShape2D" parent="Area2"]
position = Vector2( 4, -6 )
shape = SubResource( 2 )

[node name="Area3" type="Area2D" parent="."]
position = Vector2( 146, 66 )
collision_layer = 0
collision_mask = 2147483648
...

to this:

...
[node name="Area1" type="Area2D" parent="."]
position = Vector2( 65, 196 )
collision_layer = 0
collision_mask = 0

[node name="A1Collision" type="CollisionShape2D" parent="Area1"]
modulate = Color( 1, 0.717647, 0.0980392, 1 )
position = Vector2( 96, -84 )
shape = SubResource( 1 )

[node name="Area2" type="Area2D" parent="."]
position = Vector2( 228, 205 )
collision_layer = 0
collision_mask = 0

[node name="A2Collision" type="CollisionShape2D" parent="Area2"]
position = Vector2( -6, -14 )
shape = SubResource( 2 )

[node name="Area3" type="Area2D" parent="."]
position = Vector2( 146, 66 )
collision_layer = 0
collision_mask = 0
...

All the collision_layers and collision_masks are now zero. Are you saying you're having a different experience?

@chucklepie
Copy link
Author

chucklepie commented Sep 15, 2020 via email

@madmiraal
Copy link
Contributor

@chucklepie If you want to set the collision_mask or collision_layer to zero you have to use the reset button ↺ to first set it to the default: 1. Otherwise, as you suggest, just clicking on the the individual squares or checking/unchecking the named layers will only change a single bit. The other bits (visible or not) will not be changed. In your case the 32nd bit is set and invisible, and it will remain set until the reset button ↺ is used.

The question of why or how it got set to this value is a separate question, and is the basis of this issue.

@madmiraal
Copy link
Contributor

@TheOrganicRobot has found the way to reproduce the issue:

After several hours of trying to solve the issue, I believe it came from the Collision section of an Area2D node. When opening the Collision section, there are there 20 boxes for the Layer and 20 for the Mask, and also the containing darker box containing all 20 of the layer boxes. The issue is that clicking anywhere within the darker container that is NOT on one of the 20 boxes still has some sort of effect regarding the decided collision layers without triggering one of the 20 boxes to be highlighted. This can be seen by the circular "revert" arrow that shows up, as well as in the Output that displays "Set collision_layer."

@chucklepie
Copy link
Author

chucklepie commented Oct 12, 2020 via email

@Ark2000
Copy link

Ark2000 commented Mar 2, 2021

I have made a minimal bug produce project for 3.2.3 stable
minimal bug produce.zip

@madmiraal
Copy link
Contributor

@Ark2000, as described above to fix your project you need to clear the Collision Layer and Mask by using the reset button ↺ to set them to the default: 1. Then deselect the first layer/mask. If you now save the scene you will see it set to zero in the .tscn file.

The fix to prevent this from happening is included in 3.2.4.rc3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants