Emitter.spurt() throws "snapToPixelEnabled" TypeError when cache:true (works in older ZIM version)

Hi Dan,

I ran into a bug with Emitter that only appears in a newer ZIM/CreateJS version. The exact same activity code works fine in my older version but breaks in the newer one.

Error (from mobile Chrome remote debugging):

Uncaught TypeError: Cannot set properties of undefined (setting 'snapToPixelEnabled')
    at t.Emitter.spurt (zim.js)
    at my sekiller.js (the .spurt(20) call)

How I create the emitter:

js

var emitter = new Emitter({
    obj: new Poly({min:30, max:50}, [5,6,7], {min:.5, max:.7},
        ["#E74C3C","#3498DB","#F9E79F","#A04000","#F7DC6F","#82E0AA"]),
    force: 2,
    gravity: -8.5,
    startPaused: true,
    cache: true        // this is what triggers it
});

emitter.loc({target:{x:..., y:...}, container:stage}).spurt(20);

What happens: When cache is true, calling .spurt() throws the error above and no particles appear. It looks like an internal object is undefined at the point where snapToPixelEnabled is being set, so the cache/bitmap path fails.

Key detail — it's version-dependent:

  • Older ZIM + CreateJS (my 2nd-grade project): same code works, particles appear.
  • Newer ZIM + CreateJS (my 3rd-grade project): same code throws the error.

So this looks like a regression between the two versions.

Workaround I found: Setting cache: false makes it work again, which confirms the problem is in the cache path.

I originally used cache: mobile() for performance on phones, so I'd love to keep caching working. Could you check whether spurt() handles the cached-object case correctly in the newer build?

I can send the exact version numbers (zim.VERSION and the CreateJS version) for both projects if that helps.

Thanks!

Just tested, it worked in 017 and breaks in 018. Will look into it now.

image

Got it - this was added. I guess the stage is not there yet until the Emitter is added to the stage - so we will move this to the added event. Adjusting now...

Okay - that is fixed - sorry for the bug. We fixed it in 020 but have not gone back to 018 and 019 - that is a little complicated to do, and if it has not been reported perhaps nobody has updated their ZIM when using cache true on the Emitter.

So update to 020 and refresh cache. Cheers.

1 Like

Okay. The problem is solved. Thank you very much.

1 Like