CATROID-1640 Reset embroidery, plot, and laser drawing state on fresh starts#5186
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses stale embroidery/plot/laser runtime state being unintentionally reused across fresh executions by introducing an explicit drawing-state reset on Sprite and invoking it on fresh-start lifecycle paths.
Changes:
- Added
Sprite.resetDrawingState()to reinitialize pen/plot/running-stitch runtime objects and reused it fromresetSprite(). - Reset drawing state when starting a scene fresh (
startScene) and when restarting/reloading a project (reloadProject). - Added a regression unit test covering the drawing-state reset behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
catroid/src/test/java/org/catrobat/catroid/test/content/SpriteDrawingStateResetTest.kt |
New unit test verifying that resetDrawingState() reinitializes pen configuration, plot state, and running stitch state. |
catroid/src/main/java/org/catrobat/catroid/stage/StageListener.java |
Invokes resetDrawingState() on sprites for fresh-start flows (start scene, project reload). |
catroid/src/main/java/org/catrobat/catroid/content/Sprite.java |
Introduces resetDrawingState() and delegates drawing-related reinitialization from resetSprite() to this helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
720b22b to
fcb4dfd
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@dorianpercic Should I rewrite the Java production code files to Kotlin here as well? They seem a bit broad for the narrow topic of this PR, and would require more extensive testing. Please let me know what you think. |
No I think our convention was that only new files should be implemented in Kotlin. Maybe in future, to accelerate refactoring to Kotlin, especially with today's LLM capabilities, we might change the policy to let rewrite each changed file immediately to Kotlin, but this might need some more testing on how good this works. Maybe there exists some tools already which alleviate this? |
OK. I've included in my AGENTS.md file the following lines:
|
In refactoring tickets (example: https://catrobat.atlassian.net/browse/CATROID-1548) we have these guidelines:
maybe we can add this, and especially Null Safety handling, as well. |
There was a problem hiding this comment.
Can I ask, what this PR actually really fixes? Since all there is done now is instead of doing:
penConfiguration = new PenConfiguration();
plot = new Plot();
runningStitch = new RunningStitch();
a new function is called, which does exactly the same. I might be confused, but I don't see what this really changes now. Or maybe only the PR description does not match the content; if it's only a small refactoring ticket though, then I get it.
You are right, thanks a lot for that save! The apk Katja and I tested was created before a "cleanup" in response to the “redundant reset” review by Copilot. Shouldn't have done that, the order was wrong... The supporting evidence from reflog/history is:
This also revealed the insufficiency of the current test. I will by fixing that in my next commit. |
3ce95a5 to
bc71082
Compare
|
|
@dorianpercic Thanks again. The PR has been updated, and it now contains the actual fix again. What changed:
Why the old test was not good enough:
Why the new test is more meaningful:
So the two commits now tell the intended story:
And in addition to the automated regression test, I also manually verified the rebuilt APK on-device just now: the embroidery start behavior is correct again, so eyeballs 1.0 also confirm the fix. 👀 |
dorianpercic
left a comment
There was a problem hiding this comment.
Thanks, now it's clear! :)



Summary
This PR fixes stale drawing/stitch runtime state being reused across fresh executions.
https://catrobat.atlassian.net/browse/CATROID-1640
If a project ended while a running stitch, plot, cut, or engrave mode was still active, the next fresh run could inherit that old state and create an unintended initial segment from the previous endpoint to the new start position.
The fix resets that runtime state when execution is supposed to start from a blank slate, while preserving the existing behavior for resume-style flows.
Why this approach
The underlying issue was not in the stitch/plot geometry itself, but in sprite runtime state surviving longer than intended.
Sprite keeps drawing-related runtime objects such as:
Those objects should be preserved for resume behavior like pause/continue and Continue scene, but they must be reset for fresh starts such as project restart and Start scene.
To keep that distinction explicit, this PR introduces a dedicated drawing-state reset helper on Sprite and uses it only on fresh-start lifecycle paths.
Changes
Explicitly reset drawing state on:
Result
Fresh runs now start with clean embroidery/plot/laser state, even if no explicit stop brick was used in the previous execution.
This covers:
Testing
Verified with:
./gradlew :catroid:testCatroidDebugUnitTest --tests org.catrobat.catroid.test.content.SpriteDrawingStatTest on phone: screen recording before and after fix: https://photos.app.goo.gl/yGBKrRXvmYrQhcev6
Your checklist for this pull request
Please review the contributing guidelines and wiki pages of this repository.