Nasty bug in stageBounds and/or group:insert() and/or resetTransform

The weirdest thing that screwed me over big time…

I tried to distill it in a very simple program to print out the stangeBounds.xMin value of a rectangle object before and after inserting it in a group:

[lua]local g = display.newGroup()
g.xOrigin = 175; g.yOrigin = 235
local r = display.newRoundedRect(0, 0, 50, 50, 0 )
print(r.stageBounds.xMin)
g:insert(r,true)
print(r.stageBounds.xMin)[/lua]

which prints out:
0
175

then we comment out the first print statement and run it again:

[lua]local g = display.newGroup()
g.xOrigin = 175; g.yOrigin = 235
local r = display.newRoundedRect(0, 0, 50, 50, 0 )
–print(r.stageBounds.xMin)
g:insert(r,true)
print(r.stageBounds.xMin)[/lua]

Now it prints out:

150

So asking for a display object’s property value, changes its value…

Now… if we use the insert without the resetTransform to true, then it will print out 175 in either case.

Unless I completely misunderstood how to use stageBounds.xMin, that feels like a very nasty bug.

I’d really appreciate it if someone could confirm this “feature” on their machine.

-FrankS.

PS. I’ve seen weird behavior with this resetTransform==true, but it is difficult to reproduce in a way that I can understand what it does and why… are there other bugs reported about this? [import]uid: 8093 topic_id: 7712 reply_id: 307712[/import]

I checked and may confirm this bug on Corona SDK 268 and 309.

PS. I saw different result with resetTransfrom as described here [import]uid: 9058 topic_id: 7712 reply_id: 27419[/import]

@ Andriy Pertsov - Thanks for checking.

I was also made aware by kam187osx on irc that stageBounds has been deprecated in favor of contentBounds.

However, the same bug shows up with contentBounds - please try the snippet with and without the commented print statement:

[lua]local g = display.newGroup()
g.xOrigin = 175; g.yOrigin = 235
local r = display.newRoundedRect(0, 0, 50, 50, 0 )
–print(r.stageBounds.xMin)
g:insert(r, true)
print(r.contentBounds.xMin)[/lua]

In addition, the documentation on “http://developer.anscamobile.com/content/display-objects” is outdated as it only talks about “stageBounds”.

-FrankS.
[import]uid: 8093 topic_id: 7712 reply_id: 27424[/import]

Unless I completely misunderstood how to use stageBounds.xMin, that feels like a very nasty bug.

You didn’t misunderstand stageBounds, but you did misunderstand resetTransform. What you found isn’t a bug, it is correct but kind of confusing behavior. You see, when you first create the rectangle the position is based on the top left corner, but after that it is positioned by the center. Then that resetTransform property repositions the object based on the parent group.

The parent group is positioned at 175. Then the rectangle is inserted and it’s position is reset to 0. However that’s 0 relative to the parent group, so it’s 175 relative to the stage. And then that position is for the center of the rectangle; since the rectangle is 50 units wide, that means the left edge is at 150 relative to the stage.

Note the documentation here about the resetTransform parameter:
http://developer.anscamobile.com/reference/index/groupinsert

the documentation on “http://developer.anscamobile.com/content/display-objects” is outdated as it only talks about “stageBounds”.

Yeah a lot of the docs are outdated, there’s a lot of stuff that needs updated. Like, I didn’t realize the ui.lua that’s in Corona’s samples is outdated until someone told me after I had posted code with the old ui module. [import]uid: 12108 topic_id: 7712 reply_id: 27464[/import]

Sorry, but please read my postings again because you missed the bug!!!

It is not about “resetTransform” and how it supposed to work, it is about the fact that reading or printing the contentBounds.xMin value before the insert(r,true), changes the outcome after the insert.

Something is wrong in the contentBounds.xMin getter function together with the insert() with resetTransform.

-FS.
[import]uid: 8093 topic_id: 7712 reply_id: 27468[/import]

I posted that from work so I wasn’t able to actually run your code. Now that I’ve run it, I’m noticing that the rectangle actually changes position before and after commenting out the first print line. It looks the reference point gets centered. The bug looks like calling contentBounds changes the object’s reference point, which it shouldn’t be doing. [import]uid: 12108 topic_id: 7712 reply_id: 27498[/import]