Finalize events not dispatching on children when group is dispatched ?

Thanks for sharing! I knew Sergey was good, but wasn’t aware of this particular little gem…

Oh, it got updated.

Please use this version, it’s more robust:

[lua]

– Fix problem that finalize event is not called for children objects when group is removed

local function finalize(event)

    local g = event.target

    for i = 1, g.numChildren do

        if g[i]._tableListeners and g[i]._tableListeners.finalize then

            for j = 1, #g[i]._tableListeners.finalize do

                g[i]._tableListeners.finalize[j]:dispatchEvent{name = ‘finalize’, target = g[i]}

            end

        end

        if g[i]._functionListeners and g[i]._functionListeners.finalize then

            for j = 1, #g[i]._functionListeners.finalize do

                g[i]._functionListeners.finalize[j]({name = ‘finalize’, target = g[i]})

            end

        end

        if g[i].numChildren then

            finalize{target = g[i]}

        end

    end

end

local newGroup = display.newGroup

function display.newGroup()

    local g = newGroup()

    g:addEventListener(‘finalize’, finalize)

    return g

end

[/lua]

Rob, my initial bug report is “Case 30028”.

Hi Rob,

Just bumping my thread to see if we can maybe get a little love from the engineers. I know it’s not really your call, but I’m just trying to be the squeaky wheel that gets the grease - especially since they can just replicate Sergey’s awesome fix at the SDK level. I’m less concerned about my own projects (I can use Sergey’s fix, obviously), but once this is fixed in the SDK I’ll be able to confidently put out a couple of modules I want to release to the community that require a finalize event to be 100% effective.

Thanks!

Since there is a workaround for this, we need to fix more critical bugs, like all of these iOS 8 bugs.  Perhaps bump this again in a couple of weeks?

Rob

Fair enough. Bad timing on my part. Thanks for the reply!

I should have kept the workaround secret… haha.

@Sergey: Ha! In the meantime, I think I might just plug in your workaround at the top of my modules in the interest of getting them out there. I’ll be sure to give you credit, of course! (and the modules will be free, so it’s not like I’m profiting off your work.) Thanks as always for your contributions, Sergey!

Beware, when Corona finally fixes the bug, my fix and your modules with it might stop working.

So be sure to tell them to check for updates. Or make a built in notifier - network.request() your file in say dropbox module_version.txt, and if current module version is lower than that is available, print() or showAlert() message asking to update. But only when it’s simulator running.

Hi Sergey,

Your last post got me thinking, so I whipped up a slight modification to your workaround that checks to see if the issue is fixed before implementing your (awesome) fix. So this way your code is future-proofed. Here it is, in case you want to check it out:

[lua]

– SERGEY’S FINALIZE FIX:

local function fixFinalize()

   local function finalize(event)

      local g = event.target

      for i = 1, g.numChildren do

         if g[i]._tableListeners and g[i]._tableListeners.finalize then

            for j = 1, #g[i]._tableListeners.finalize do

               g[i]._tableListeners.finalize[j]:dispatchEvent{name = ‘finalize’, target = g[i]}

            end

         end

         if g[i]._functionListeners and g[i]._functionListeners.finalize then

            for j = 1, #g[i]._functionListeners.finalize do

               g[i]._functionListeners.finalize[j]({name = ‘finalize’, target = g[i]})

            end

         end

         if g[i].numChildren then

            finalize{target = g[i]}

         end

      end

   end

   local newGroup = display.newGroup

   function display.newGroup()

      local g = newGroup()

      g:addEventListener(‘finalize’, finalize)

      return g

   end

end

– CHECK TO SEE IF FIX IS NEEDED:

local finalizeFixed = false

local testGroup = display.newGroup()

testGroup.isVisible = false

local testObject = display.newRect(testGroup, 0, 0, 1, 1)

function testObject:finalize(self, event)

   finalizeFixed = true

   print(“no longer any need to fix finalize() - thanks Corona Labs!”)

end

display.remove(testGroup)

timer.performWithDelay(1, function()

   if not finalizeFixed then fixFinalize() end

   finalizeFixed, testGroup, testObject = nil, nil, nil

end)

[/lua]

Thanks again!

Hi Rob,

Just a friendly bump on this post to see if there’s any sort of ETA on having this bug fixed.

To shed some light on why I’m so antsy about it: I’ve put together what I think is a nice little module to share with the community that adds an endless “looping” scrollView with one line of code. But since it utilizes a Runtime listener, I don’t want to release it until this bug is fixed, so that I don’t need to make people go through the extra step of manually removing the looping scrollView object when they destroy the scrollView’s parent/scene (I remove the Runtime listener in the scrollView’s finalize event listener). Not the biggest biggie, I know, but just thought I’d check in.

Thanks as always!

It’s still in the queue to be worked on.

Rob

Hi Rob,

Just bumping my thread to see if we can maybe get a little love from the engineers. I know it’s not really your call, but I’m just trying to be the squeaky wheel that gets the grease - especially since they can just replicate Sergey’s awesome fix at the SDK level. I’m less concerned about my own projects (I can use Sergey’s fix, obviously), but once this is fixed in the SDK I’ll be able to confidently put out a couple of modules I want to release to the community that require a finalize event to be 100% effective.

Thanks!

Since there is a workaround for this, we need to fix more critical bugs, like all of these iOS 8 bugs.  Perhaps bump this again in a couple of weeks?

Rob

Fair enough. Bad timing on my part. Thanks for the reply!

I should have kept the workaround secret… haha.

@Sergey: Ha! In the meantime, I think I might just plug in your workaround at the top of my modules in the interest of getting them out there. I’ll be sure to give you credit, of course! (and the modules will be free, so it’s not like I’m profiting off your work.) Thanks as always for your contributions, Sergey!

Beware, when Corona finally fixes the bug, my fix and your modules with it might stop working.

So be sure to tell them to check for updates. Or make a built in notifier - network.request() your file in say dropbox module_version.txt, and if current module version is lower than that is available, print() or showAlert() message asking to update. But only when it’s simulator running.

Hi Sergey,

Your last post got me thinking, so I whipped up a slight modification to your workaround that checks to see if the issue is fixed before implementing your (awesome) fix. So this way your code is future-proofed. Here it is, in case you want to check it out:

[lua]

– SERGEY’S FINALIZE FIX:

local function fixFinalize()

   local function finalize(event)

      local g = event.target

      for i = 1, g.numChildren do

         if g[i]._tableListeners and g[i]._tableListeners.finalize then

            for j = 1, #g[i]._tableListeners.finalize do

               g[i]._tableListeners.finalize[j]:dispatchEvent{name = ‘finalize’, target = g[i]}

            end

         end

         if g[i]._functionListeners and g[i]._functionListeners.finalize then

            for j = 1, #g[i]._functionListeners.finalize do

               g[i]._functionListeners.finalize[j]({name = ‘finalize’, target = g[i]})

            end

         end

         if g[i].numChildren then

            finalize{target = g[i]}

         end

      end

   end

   local newGroup = display.newGroup

   function display.newGroup()

      local g = newGroup()

      g:addEventListener(‘finalize’, finalize)

      return g

   end

end

– CHECK TO SEE IF FIX IS NEEDED:

local finalizeFixed = false

local testGroup = display.newGroup()

testGroup.isVisible = false

local testObject = display.newRect(testGroup, 0, 0, 1, 1)

function testObject:finalize(self, event)

   finalizeFixed = true

   print(“no longer any need to fix finalize() - thanks Corona Labs!”)

end

display.remove(testGroup)

timer.performWithDelay(1, function()

   if not finalizeFixed then fixFinalize() end

   finalizeFixed, testGroup, testObject = nil, nil, nil

end)

[/lua]

Thanks again!

At long last, the finalize bug was fixed with Corona daily build # 2015.2544! Marking this topic as solved. Woohoo!