ymobe/rapanui — pull request #35 by Odie (2012-04-11 06:49:55+00:00)
Title: RNObject:remove patches

Hi there,

I came across two problems with RNObject:remove recently when working with rectangles. I'm submitting them as a single pull request. The problems are outlined below.

# RNObject:remove throws exception when parentGroup is nil
Specifically, several rectangles were created with RNFactory.createRect(). The create function seemed careful not to set the parentGroup field. However, the remove function does not check for this condition, assumes parentGroup is always valid, and calls a function on parentGroup, which is nil.

# RNScreen:removeRNObject doesn't update MOAI prop -> RNObject mapping
It looks like rapanui relies on the RNScreen.sprites table to maintain a MOAI prop -> RNObject mapping. It's then used to process touch input, using MOAI for object picking, then using the sprites table to retrieve the corresponding RNObject.

On object removal, removeRNObject function does properly update the objects' index to itself in the sprites table. But, it doesn't update the MOAI prop's index to their corresponding RNObject in the sprites table.

The end result is... as soon as an object is removed, object picking cease to function correctly. Touching one object would cause the touch handler on a "random" object to be fired instead.