Snapshots

Why does my snapshot go blank when I call :invalidate()?

Do the objects placed in it get removed from memory?

That’s weird.

snapshot:invalidate() should clear the current contents and redraw all children that were added with snapshot.group:insert().

I don’t see this problem with my apps that use snapshots.

What build of Corona are you using (also iOS or Android)?

I genuinely can’t think what the hell I was doing, but since you posted your comment everything has started working for me. I absolutely swear that previously it was as if the display objects I was adding to the snapshot’s group were being erased and not re-rendered and I could not figure out why. Anyway, here is the test code I was using. It works now, but the short of it is that I was trying to use three circles (r, g and b) with blendMode = add (on top of a black, normal circle) to generate different colours. The snapshot was being used to add a glow effect to the circles. Let me know what you think. I’m hoping that the learning curve which I’ve just navigated is common, but maybe I’m just dim…

local function applyGlow(snapshot) snapshot.fill.effect = "filter.bloom" snapshot.fill.effect.levels.white = 0.8 snapshot.fill.effect.levels.black = 0.4 snapshot.fill.effect.levels.gamma = 1 snapshot.fill.effect.add.alpha = 0.8 snapshot.fill.effect.blur.horizontal.blurSize = 40 snapshot.fill.effect.blur.horizontal.sigma = 140 snapshot.fill.effect.blur.vertical.blurSize = 40 snapshot.fill.effect.blur.vertical.sigma = 140 end local function test() local snap = display.newSnapshot( 200, 200 ) snap.x, snap.y = 200, 200 snap.canvasMode = "discard" -- local black = display.newCircle( 0,0 , 50 ) -- black.fill = {0,0,0} local a = display.newCircle( 0,0 , 50 ) local b = display.newCircle( 0,0, 50 ) local c = display.newCircle( 0,0, 50 ) a.fill = {1,0,0,0} b.fill = {0,1,0} c.fill = {0,0,1} a.fill.blendMode = "add" b.fill.blendMode = "add" c.fill.blendMode = "add" -- snap.group:insert( black ) snap.group:insert( a ) snap.group:insert( b ) snap.group:insert( c ) applyGlow( snap ) timer.performWithDelay( 1000, function() snap:invalidate() -- black = display.newCircle( 0,0 , 50 ) -- black.fill = {0,0,0} -- a = display.newCircle( 0,0 , 50 ) -- b = display.newCircle( 0,0, 50 ) -- c = display.newCircle( 0,0, 50 ) -- a.fill = {1,0,0,0} -- b.fill = {0,1,0,0} c.fill = {0,0,1,0} -- a.fill.blendMode = "add" -- b.fill.blendMode = "add" -- c.fill.blendMode = "add" -- snap.group:insert( black ) -- snap.group:insert( a ) -- snap.group:insert( b ) -- snap.group:insert( c ) applyGlow( snap ) print("done") end, 1 ) end test()

The only issue I can see in your code is in your performWithDelay(). 

It’s commented out now, but if you’d uncomment everything it would probably appear to show a cyan circle for 1 second, and then it would “disappear” or go black. You’re adding a black circle and then the three other circles with alpha 0. The new black circle would cover the previous children and the three other new ones would be invisible due to their alpha.

snapshot:invalidate() does not remove the current children, which means in your code with everything uncommented you’ll end up with a snapshot including 8 children. (black, a ,b, c, black, a, b, c)

Note: Setting canvasMode to “discard” does nothing as you’re not manipulating the canvas (snapshot.canvas). I haven’t used the canvas myself in any projects yet, but as I understand it’s only useful if you want to create light-trail effects etc.

@ingemar Have you seen my other post on this? Would love your input here, if you can, please?

http://t.co/gczoNSGiAH

That’s weird.

snapshot:invalidate() should clear the current contents and redraw all children that were added with snapshot.group:insert().

I don’t see this problem with my apps that use snapshots.

What build of Corona are you using (also iOS or Android)?

I genuinely can’t think what the hell I was doing, but since you posted your comment everything has started working for me. I absolutely swear that previously it was as if the display objects I was adding to the snapshot’s group were being erased and not re-rendered and I could not figure out why. Anyway, here is the test code I was using. It works now, but the short of it is that I was trying to use three circles (r, g and b) with blendMode = add (on top of a black, normal circle) to generate different colours. The snapshot was being used to add a glow effect to the circles. Let me know what you think. I’m hoping that the learning curve which I’ve just navigated is common, but maybe I’m just dim…

local function applyGlow(snapshot) snapshot.fill.effect = "filter.bloom" snapshot.fill.effect.levels.white = 0.8 snapshot.fill.effect.levels.black = 0.4 snapshot.fill.effect.levels.gamma = 1 snapshot.fill.effect.add.alpha = 0.8 snapshot.fill.effect.blur.horizontal.blurSize = 40 snapshot.fill.effect.blur.horizontal.sigma = 140 snapshot.fill.effect.blur.vertical.blurSize = 40 snapshot.fill.effect.blur.vertical.sigma = 140 end local function test() local snap = display.newSnapshot( 200, 200 ) snap.x, snap.y = 200, 200 snap.canvasMode = "discard" -- local black = display.newCircle( 0,0 , 50 ) -- black.fill = {0,0,0} local a = display.newCircle( 0,0 , 50 ) local b = display.newCircle( 0,0, 50 ) local c = display.newCircle( 0,0, 50 ) a.fill = {1,0,0,0} b.fill = {0,1,0} c.fill = {0,0,1} a.fill.blendMode = "add" b.fill.blendMode = "add" c.fill.blendMode = "add" -- snap.group:insert( black ) snap.group:insert( a ) snap.group:insert( b ) snap.group:insert( c ) applyGlow( snap ) timer.performWithDelay( 1000, function() snap:invalidate() -- black = display.newCircle( 0,0 , 50 ) -- black.fill = {0,0,0} -- a = display.newCircle( 0,0 , 50 ) -- b = display.newCircle( 0,0, 50 ) -- c = display.newCircle( 0,0, 50 ) -- a.fill = {1,0,0,0} -- b.fill = {0,1,0,0} c.fill = {0,0,1,0} -- a.fill.blendMode = "add" -- b.fill.blendMode = "add" -- c.fill.blendMode = "add" -- snap.group:insert( black ) -- snap.group:insert( a ) -- snap.group:insert( b ) -- snap.group:insert( c ) applyGlow( snap ) print("done") end, 1 ) end test()

The only issue I can see in your code is in your performWithDelay(). 

It’s commented out now, but if you’d uncomment everything it would probably appear to show a cyan circle for 1 second, and then it would “disappear” or go black. You’re adding a black circle and then the three other circles with alpha 0. The new black circle would cover the previous children and the three other new ones would be invisible due to their alpha.

snapshot:invalidate() does not remove the current children, which means in your code with everything uncommented you’ll end up with a snapshot including 8 children. (black, a ,b, c, black, a, b, c)

Note: Setting canvasMode to “discard” does nothing as you’re not manipulating the canvas (snapshot.canvas). I haven’t used the canvas myself in any projects yet, but as I understand it’s only useful if you want to create light-trail effects etc.

@ingemar Have you seen my other post on this? Would love your input here, if you can, please?

http://t.co/gczoNSGiAH