diff --git a/modules/particles/src/SkParticleBinding.cpp b/modules/particles/src/SkParticleBinding.cpp index e1a45324a1..1f41d5c454 100644 --- a/modules/particles/src/SkParticleBinding.cpp +++ b/modules/particles/src/SkParticleBinding.cpp @@ -100,11 +100,12 @@ public: void call(int index, float* arguments, float* outReturn) override { SkScalar len = fPath->fTotalLength * arguments[0]; int idx = 0; - while (idx < fPath->fContours.count() && len > fPath->fContours[idx]->length()) { + while (idx < fPath->fContours.count() - 1 && len > fPath->fContours[idx]->length()) { len -= fPath->fContours[idx++]->length(); } SkVector localXAxis; - if (!fPath->fContours[idx]->getPosTan(len, (SkPoint*)outReturn, &localXAxis)) { + if (idx >= fPath->fContours.count() || + !fPath->fContours[idx]->getPosTan(len, (SkPoint*)outReturn, &localXAxis)) { outReturn[0] = outReturn[1] = 0.0f; localXAxis = { 1, 0 }; } diff --git a/modules/particles/src/SkParticleEffect.cpp b/modules/particles/src/SkParticleEffect.cpp index ff3b5d7d81..d78ede5c84 100644 --- a/modules/particles/src/SkParticleEffect.cpp +++ b/modules/particles/src/SkParticleEffect.cpp @@ -278,6 +278,7 @@ void SkParticleEffect::runParticleScript(double now, const char* entry, int star value->setRandom(randomBase); value->setEffect(this); } + memcpy(&fParticleUniforms[1], &fState.fAge, sizeof(EffectState)); SkAssertResult(byteCode->runStriped(fun, count, args, SkParticles::kNumChannels, nullptr, 0, fParticleUniforms.data(), @@ -321,7 +322,6 @@ void SkParticleEffect::advanceTime(double now) { SkASSERT(!this->particleCode() || this->particleCode()->getUniformLocation("effect.age") == 1); fEffectUniforms[0] = deltaTime; fParticleUniforms[0] = deltaTime; - memcpy(&fParticleUniforms[1], &fState.fAge, sizeof(EffectState)); // Is this the first update after calling start()? // Run 'effectSpawn' to set initial emitter properties. diff --git a/resources/particles/writing.json b/resources/particles/writing.json new file mode 100644 index 0000000000..43682d5857 --- /dev/null +++ b/resources/particles/writing.json @@ -0,0 +1,43 @@ +{ + "MaxCount": 4000, + "Drawable": { + "Type": "SkCircleDrawable", + "Radius": 2 + }, + "EffectCode": [ + "void effectSpawn(inout Effect effect) {", + " effect.lifetime = 4;", + "}", + "", + "void effectUpdate(inout Effect effect) {", + " effect.color.r = 0;", + " effect.color.g = 1 - effect.age;", + " effect.color.b = effect.age;", + "", + " effect.rate = effect.age < 0.75 ? 800 : 0;", + "}", + "" + ], + "Code": [ + "uniform float2 mouse_pos;", + "", + "void spawn(inout Particle p) {", + " p.lifetime = 4;", + " p.pos = mouse_pos;", + " p.frame = effect.age / 0.75 + mix(-0.05, 0.05, rand);", + "}", + "", + "void update(inout Particle p) {", + " p.pos = mix(p.pos, text(p.frame).xy, 0.05);", + "}", + "" + ], + "Bindings": [ + { + "Type": "SkTextBinding", + "Name": "text", + "Text": "HELLO WORLD", + "FontSize": 96 + } + ] +} \ No newline at end of file