peter-kish / gloot

A universal inventory system for the Godot game engine.
MIT License
625 stars 28 forks source link

Bug: set_rect_backgound array out of bounds error. #193

Closed LeeWannacott closed 6 months ago

LeeWannacott commented 6 months ago

Its called by _highlight_grabbed_item.

https://github.com/peter-kish/gloot/assets/49783296/c257b465-9628-480b-a8e1-278948c3efdd

image

peter-kish commented 6 months ago

Ugh, those negative rect coordinates don't look good...

A few questions:

  1. So, this randomly happens while dragging an item across the screen? Or does it happen on a drop?
  2. How often does it happen?
  3. Did you start noticing this after the last release?
LeeWannacott commented 6 months ago

Ugh, those negative rect coordinates don't look good...

A few questions:

  1. So, this randomly happens while dragging an item across the screen? Or does it happen on a drop?
  2. How often does it happen?
  3. Did you start noticing this after the last release?

1 when dragging, I'm not dropping; seems random. 3 I copied over from master to get your signals fix. 2 I can get it to happen quite easily. My guess the bugs always been there though. I'll investigate further tomorrow. Update: I think it has been introduced recently.

peter-kish commented 6 months ago

I wasn't really able to reproduce this, but I made some assumptions on how it could happen and added some additional checks. The changes are on the dev_v2.4.8 branch. I'll do some more testing and eventually merge it to master. I hope it will fix the issue.

LeeWannacott commented 6 months ago

I wasn't really able to reproduce this, but I made some assumptions on how it could happen and added some additional checks. The changes are on the dev_v2.4.8 branch. I'll do some more testing and eventually merge it to master. I hope it will fix the issue.

Seems to fix the issue :tada: (before when I brought my item to about halfway on the screen (vertically whilst dragging) it happened and doesn't now) , However there now seems to be a case of gigantasauras rex and the icon is offcentre now from the mouse cursor...

https://github.com/peter-kish/gloot/assets/49783296/198cd002-f822-4d3e-95df-c82e0c7272a2

Also there is a separate issue from this that I have been meaning to report, which is that the items icon dragged from the inventory of my shop keepers whilst dragging isn't centre its like off-screen somewhere; I think its caused by the shopkeepers being on a different canvas layer (I think they default to 0) than my players inventory (1), because I managed to fix it on one of them. I guess this is my problem to fix; it is a little bit annoying though... (I guess I just don't understand how using a different canvas layer would effect it?; it should only effect the layer/order of drawing not the position?)

peter-kish commented 6 months ago

I played around with this a little, but couldn't reproduce the oversized drag icon problem. Can you give me some additional information about your scene (scaling, canvas layers etc.)? Edit: I managed to reproduce the issue. Hope I'll come up with a fix soon.

As for the canvas layer problem, it seems to be a known Godot issue: https://github.com/godotengine/godot-docs/issues/4086 The issue is related to the camera position, but the same seems to happen if you have a canvas layer that is transformed in some way (non-zero offset and/or scale that is different from (1,1)). There are workarounds for this but they don't look very elegant ☹️. But since the issue is open since 2020, I don't expect it to be fixed anytime soon, so I might implement one of these workarounds after all. Until then the only solution is to keep the canvas layer offset and scale at default.

LeeWannacott commented 6 months ago

I managed to reproduce the issue. Hope I'll come up with a fix soon.

Sweet, my project is getting complicated; it can be hard to figure out what is causing bugs.

canvas layer that is transformed in some way (non-zero offset and/or scale that is different from (1,1))

I think my canvas layers are default, but they are in nested scenes, so they probably belong to different Viewports.

peter-kish commented 6 months ago

Should be fixed in v2.4.8