Godot: Game Crash on set custom mouse cursor

Created on 7 May 2018  路  18Comments  路  Source: godotengine/godot

Master,x11

[1] /lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f6a8f6ab4b0] (??:0)
[2] OS_X11::set_custom_mouse_cursor(Ref const&, OS::CursorShape, Vector2 const&) (/godot/platform/x11/os_x11.cpp:2393)
[3] InputDefault::set_custom_mouse_cursor(Ref const&, Input::CursorShape, Vector2 const&) (/godot/main/input_default.cpp:611)
[4] MethodBind3 const&, Input::CursorShape, Vector2 const&>::call(Object, Variant const, int, Variant::CallError&) (/godot/core/method_bind.gen.inc:2151 (discriminator 26))
[5] Object::call(StringName const&, Variant const
, int, Variant::CallError&) (/godot/core/object.cpp:914 (discriminator 1))
[6] Variant::call_ptr(StringName const&, Variant const, int, Variant
, Variant::CallError&) (/godot/core/variant_call.cpp:1022 (discriminator 1))
[7] GDScriptFunction::call(GDScriptInstance, Variant const
, int, Variant::CallError&, GDScriptFunction::CallState) (/godot/modules/gdscript/gdscript_function.cpp:811)
[8] GDScriptInstance::call_multilevel(StringName const&, Variant const, int) (/godot/modules/gdscript/gdscript.cpp:1167)
[9] Object::call_multilevel(StringName const&, Variant const
, int) (/godot/core/object.cpp:744)
[10] SceneTree::_call_input_pause(StringName const&, StringName const&, Ref const&) (/godot/scene/main/scene_tree.cpp:898)
[11] Viewport::input(Ref const&) (/godot/scene/main/viewport.cpp:2349 (discriminator 4))
[12] Viewport::_vp_input(Ref const&) (/godot/scene/main/viewport.cpp:1214)
[13] MethodBind1 const&>::call(Object*, Variant const, int, Variant::CallError&) (/godot/core/method_bind.gen.inc:729 (discriminator 12))
[14] Object::call(StringName const&, Variant const
, int, Variant::CallError&) (/godot/core/object.cpp:914 (discriminator 1))
[15] Object::call(StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) (/godot/core/object.cpp:839)
[16] SceneTree::call_group_flags(unsigned int, StringName const&, StringName const&, Variant const&, Variant const&, Variant const&, Variant const&, Variant const&) (/godot/scene/main/scene_tree.cpp:251)
[17] SceneTree::input_event(Ref const&) (/godot/scene/main/scene_tree.cpp:407 (discriminator 6))
[18] InputDefault::_parse_input_event_impl(Ref const&, bool) (/godot/main/input_default.cpp:392)
[19] InputDefault::parse_input_event(Ref const&) (/godot/main/input_default.cpp:260)
[20] OS_X11::process_xevents() (/godot/platform/x11/os_x11.cpp:1958 (discriminator 3))
[21] OS_X11::run() (/godot/platform/x11/os_x11.cpp:2520)
[22] /godot/bin/godot.x11.tools.64(main+0xd3) [0xf113e9] (/godot/platform/x11/godot_x11.cpp:56)
[23] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7f6a8f696830] (??:0)
[24] /godot/bin/godot.x11.tools.64(_start+0x29) [0xf11249] (??:?)

Steps:

    var img = Image.new()
    img.create(1,1,true,Image.FORMAT_RGBA8)
    Input.set_custom_mouse_cursor(img)

OR

    var img = Image.new()
    Input.set_custom_mouse_cursor(img)
bug linuxbsd porting

Most helpful comment

You're good at trying bad code to find missing parameter checks :P

CC @guilhermefelipecgs. The method should check that the input image is valid (here it's not, it has no image data).

All 18 comments

You're good at trying bad code to find missing parameter checks :P

CC @guilhermefelipecgs. The method should check that the input image is valid (here it's not, it has no image data).

@akien-mga I did this for 2.1 and forgot to do it on master ^^. I'll port this #18362 for 3.x, but I don't know if AtlasTexture will be changed in 3.1, it's ok?

I think AtlasTexture is still the same in 3.0 and 3.1, so it should be fine.

How can I reset the cursor to default? I tried this.

Input.set_custom_mouse_cursor(load("res://some-icon.png"))
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
Input.set_custom_mouse_cursor(null)

I think this is not possible in this moment :sweat_smile:. I'll implement.

I will reuse this issue once more.

This bad code lets the ram grow and grow and ... not sure if this is an issue of the function or something general. I am currently not on master branch so maybe this is already fixed.

func _process(delta):
Input.set_custom_mouse_cursor(load("res://icon.png"))

@AlexHolly I can't reproduce it. Tried in stable and in master and the RAM usage does not grow. I don't see how this code could lead to a memory leak since resources are loaded from disk to memory only once.

@vnen I am on master now and it still happens, x11 make sure to place it on _process

I was able to reproduce this memory leak on master. I'll try to fix that.

@AlexHolly Do you know if this also happens on windows?

@guilhermefelipecgs Nope I could give it a try if you have no windows installed.

No problem, I'll check here.

:( I am getting spammed by Image.lock() on get_pixel messages in a special case. I can reproduce it in my project but I am currently not able to reproduce on a minimal project. The editor tells me it is the
"Input.set_custom_mouse_cursor" function. While trying to create a minimal project I got this error.

extends Control

var image = ImageTexture.new()
func _ready():
    image.create(1,1,false,0)
    Input.set_custom_mouse_cursor(image)
[1] /lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7ffff51614b0] (??:0)
[2] PoolVector<unsigned char>::size() const (/godot/core/dvector.h:475)
[3] Image::lock() (/godot/core/image.cpp:1928)
[4] OS_X11::set_custom_mouse_cursor(Ref<Resource> const&, OS::CursorShape, Vector2 const&) (/godot/platform/x11/os_x11.cpp:2470)
[5] InputDefault::set_custom_mouse_cursor(Ref<Resource> const&, Input::CursorShape, Vector2 const&) (/godot/main/input_default.cpp:611)
[6] MethodBind3<Ref<Resource> const&, Input::CursorShape, Vector2 const&>::call(Object*, Variant const**, int, Variant::CallError&) (/godot/core/method_bind.gen.inc:2151 (discriminator 26))
[7] Object::call(StringName const&, Variant const**, int, Variant::CallError&) (/godot/core/object.cpp:914 (discriminator 1))
[8] Variant::call_ptr(StringName const&, Variant const**, int, Variant*, Variant::CallError&) (/godot/core/variant_call.cpp:1033 (discriminator 1))
[9] GDScriptFunction::call(GDScriptInstance*, Variant const**, int, Variant::CallError&, GDScriptFunction::CallState*) (/godot/modules/gdscript/gdscript_function.cpp:826)
[10] GDScriptInstance::_ml_call_reversed(GDScript*, StringName const&, Variant const**, int) (/godot/modules/gdscript/gdscript.cpp:1182)
[11] GDScriptInstance::call_multilevel_reversed(StringName const&, Variant const**, int) (/godot/modules/gdscript/gdscript.cpp:1191)
[12] Node::_notification(int) (/godot/scene/main/node.cpp:140)
[13] Node::_notificationv(int, bool) (/godot/./scene/main/node.h:46 (discriminator 14))
[14] CanvasItem::_notificationv(int, bool) (/godot/./scene/2d/canvas_item.h:140 (discriminator 3))
[15] Control::_notificationv(int, bool) (/godot/./scene/gui/control.h:51 (discriminator 3))
[16] Object::notification(int, bool) (/godot/core/object.cpp:926)
[17] Node::_propagate_ready() (/godot/scene/main/node.cpp:185)
[18] Node::_propagate_ready() (/godot/scene/main/node.cpp:174 (discriminator 2))
[19] Node::_set_tree(SceneTree*) (/godot/scene/main/node.cpp:2523)
[20] SceneTree::init() (/godot/scene/main/scene_tree.cpp:446)
[21] OS_X11::run() (/godot/platform/x11/os_x11.cpp:2590)
[22] /godot/bin/godot.x11.tools.64(main+0xd3) [0xf5b039] (/godot/platform/x11/godot_x11.cpp:56)
[23] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7ffff514c830] (??:0)
[24] /godot/bin/godot.x11.tools.64(_start+0x29) [0xf5ae99] (??:?)

This is the actual issue
image

I added another validation to ensure that the image is valid (I don't know why I didn't this before :thinking:) and hopefully this message about image lock will not appear again.

It is very strange the get_pixel thing still happens and no image invalid message.. I never change the icon.
I am still not able to reproduce on minimal project but in my project the "mouse_icon" changes without me doing anything with it.

I rotate different images but never "mouse_icon" once I applied my rotation I get the get_pixel errors and is_empty() returns true

var mouse_stop_icon = load("res://icon.png")
func _process(delta):
    print(mouse_icon.get_data().is_empty())
    Input.set_custom_mouse_cursor(mouse_icon)

Output

False
# Do roation on different image
True

I've no clue what could cause that.

Are you sure when you click in this message, the debbuger shows a line where you are using set_custom_mouse_cursor?

I think this error is gone right?

[1] /lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7ffff51614b0] (??:0) [2] PoolVector::size() const (/godot/core/dvector.h:475) [3] Image::lock() (/godot/core/image.cpp:1928) [4] OS_X11::set_custom_mouse_cursor(Ref const&, OS::CursorShape, Vector2 const&) (/godot/platform/x11/os_x11.cpp:2470) [5] InputDefault::set_custom_mouse_cursor(Ref const&, Input::CursorShape, Vector2 const&) (/godot/main/input_default.cpp:611) [6] MethodBind3 const&, Input::CursorShape, Vector2 const&>::call(Object, Variant const, int, Variant::CallError&) (/godot/core/method_bind.gen.inc:2151 (discriminator 26)) [7] Object::call(StringName const&, Variant const, int, Variant::CallError&) (/godot/core/object.cpp:914 (discriminator 1)) [8] Variant::call_ptr(StringName const&, Variant const, int, Variant, Variant::CallError&) (/godot/core/variant_call.cpp:1033 (discriminator 1)) [9] GDScriptFunction::call(GDScriptInstance, Variant const, int, Variant::CallError&, GDScriptFunction::CallState) (/godot/modules/gdscript/gdscript_function.cpp:826) [10] GDScriptInstance::_ml_call_reversed(GDScript, StringName const&, Variant const, int) (/godot/modules/gdscript/gdscript.cpp:1182) [11] GDScriptInstance::call_multilevel_reversed(StringName const&, Variant const, int) (/godot/modules/gdscript/gdscript.cpp:1191) [12] Node::_notification(int) (/godot/scene/main/node.cpp:140) [13] Node::_notificationv(int, bool) (/godot/./scene/main/node.h:46 (discriminator 14)) [14] CanvasItem::_notificationv(int, bool) (/godot/./scene/2d/canvas_item.h:140 (discriminator 3)) [15] Control::_notificationv(int, bool) (/godot/./scene/gui/control.h:51 (discriminator 3)) [16] Object::notification(int, bool) (/godot/core/object.cpp:926) [17] Node::_propagate_ready() (/godot/scene/main/node.cpp:185) [18] Node::_propagate_ready() (/godot/scene/main/node.cpp:174 (discriminator 2)) [19] Node::_set_tree(SceneTree) (/godot/scene/main/node.cpp:2523) [20] SceneTree::init() (/godot/scene/main/scene_tree.cpp:446) [21] OS_X11::run() (/godot/platform/x11/os_x11.cpp:2590) [22] /godot/bin/godot.x11.tools.64(main+0xd3) [0xf5b039] (/godot/platform/x11/godot_x11.cpp:56) [23] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7ffff514c830] (??:0) [24] /godot/bin/godot.x11.tools.64(_start+0x29) [0xf5ae99] (??:?)

Yeah that error is gone and it shows that line yes. So the issue is how my rotation replaces images I am not sure why it happens by it tells me that the Image is still locked. So it looks like the issue is not specificly the set_custom_mouse_cursor function but unlock/lock that replaces the mouse_icon image (randomly).

I get these right before the mouse_icon is beeing modified without me actually touching it.

image

Was this page helpful?
0 / 5 - 0 ratings