Skip to content

Fix skeleton bone links when copy/pasting layers (Fixes #453) - #3702

Open
locky504 wants to merge 1 commit into
synfig:masterfrom
locky504:fix-skeleton-paste
Open

locky504 wants to merge 1 commit into
synfig:masterfrom
locky504:fix-skeleton-paste

Conversation

@locky504

@locky504 locky504 commented Mar 5, 2026

Copy link
Copy Markdown

Problem

When copying and pasting skeleton layers, the bone links were not properly updated to point to the new cloned bones. This caused the pasted skeleton to reference bones from the original layer instead of its own bones.

This fixes issue #453.

Root Cause

The paste() function in LayerActionManager was only doing a simple clone() of layers without fixing the special valuenodes that skeleton layers use for bone references.

The LayerDuplicate action already had this fix, but the copy-paste functionality (Ctrl+C/Ctrl+V) was missing it.

Solution

Applied the same skeleton fix logic from LayerDuplicate::prepare() to LayerActionManager::paste():

  1. Added get_special_layer_valuenodes() - Collects skeleton bone valuenodes that need to be remapped
  2. Added replace_skeleton_valuenodes() - Fixes bone links in pasted layers to point to the correct (new) bones
  3. Updated paste() - Now collects layer mappings and applies skeleton fixes after all layers are pasted

Changes

  • Modified: synfig-studio/src/gui/actionmanagers/layeractionmanager.cpp
    • Added 87 lines
    • The fix mirrors the existing implementation in synfigapp/actions/layerduplicate.cpp

Testing

  • Logic verified against existing LayerDuplicate skeleton tests
  • The same approach is already proven in production via the Duplicate (Ctrl+D) functionality

Bounty

This PR fixes issue #453 which has a $60 bounty on Bountysource.

When copying and pasting skeleton layers, the bone links were not
properly updated to point to the new cloned bones. This caused the
pasted skeleton to reference bones from the original layer instead
of its own bones.

This fix:
- Adds get_special_layer_valuenodes() to collect skeleton bone valuenodes
- Adds replace_skeleton_valuenodes() to fix bone links in pasted layers
- Updates paste() to collect layer mappings and apply skeleton fixes

Fixes synfig#453
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug where copying and pasting skeleton layers resulted in incorrect bone references. The solution integrates robust remapping logic into the paste operation, ensuring that cloned skeleton layers correctly link to their own newly created bones, thereby maintaining animation integrity across duplicated content.

Highlights

  • Skeleton Bone Link Fix: Implemented logic to correctly update skeleton bone links when layers are copied and pasted, resolving an issue where pasted skeletons referenced bones from the original layer.
  • New Helper Functions: Added get_special_layer_valuenodes to identify skeleton bone value nodes and replace_skeleton_valuenodes to remap these nodes in cloned layers.
  • Paste Function Enhancement: Modified LayerActionManager::paste() to collect layer mappings and apply the skeleton bone link fixes after all layers have been pasted, mirroring the existing LayerDuplicate action.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • synfig-studio/src/gui/actionmanagers/layeractionmanager.cpp
    • Added get_special_layer_valuenodes function to identify special value nodes like skeleton bones for remapping.
    • Added replace_skeleton_valuenodes function to fix bone links in cloned layers by remapping value nodes.
    • Modified LayerActionManager::paste() to initialize maps for tracking original and cloned layers and value nodes.
    • Updated LayerActionManager::paste() to populate layer mapping during cloning.
    • Extended LayerActionManager::paste() to collect special value node mappings and apply skeleton bone link fixes after all layers are processed.
Activity
  • The logic for this fix was verified against existing LayerDuplicate skeleton tests.
  • The approach used is already proven in production through the Duplicate (Ctrl+D) functionality.
  • This pull request resolves issue Cannot copy a skeleton [$60] #453, which had a $60 bounty on Bountysource.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly applies the logic from LayerDuplicate to the copy-paste functionality to fix skeleton bone links. The changes are well-structured and follow the approach of the existing code. I've identified a potential crash due to an unchecked map lookup and a minor performance improvement opportunity in a lambda capture. Overall, this is a good fix that addresses the reported issue.

{
std::vector<ValueNode::RHandle> valuenodes;
if (layer->get_name() == "duplicate") {
valuenodes.push_back(layer->dynamic_param_list().find("index")->second);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The call to layer->dynamic_param_list().find("index") may return an iterator to the end of the map if "index" is not found. Dereferencing this iterator to access ->second would result in undefined behavior, likely a crash. You should add a check to ensure the iterator is valid before dereferencing it.

A similar issue might exist in synfigapp/actions/layerduplicate.cpp from where this code was copied.

		auto it = layer->dynamic_param_list().find("index");
		if (it != layer->dynamic_param_list().end()) {
			valuenodes.push_back(it->second);
		}

for (const auto& layer_pair : cloned_layer_map) {
auto cloned_layer = layer_pair.second;
replace_value_nodes(cloned_layer,
[cloned_valuenode_map](ValueNode::LooseHandle vn) -> ValueNode::LooseHandle {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The lambda captures cloned_valuenode_map by copy, which can be inefficient if the map is large. Since the map is not modified within the lambda, it's better to capture it by reference (&) to avoid an unnecessary copy.

A similar issue might exist in synfigapp/actions/layerduplicate.cpp.

							[&cloned_valuenode_map](ValueNode::LooseHandle vn) -> ValueNode::LooseHandle {

@locky504

locky504 commented Mar 5, 2026

Copy link
Copy Markdown
Author

Hi there! 👋

I noticed that this PR fixes issue #453, which had a $60 bounty on Bountysource. Since Bountysource has unfortunately shut down and filed for bankruptcy, I was wondering if there's an alternative way to claim this bounty?

Thank you for your time and for maintaining this wonderful project! 🙏

woahwhattheheck added a commit to woahwhattheheck/synfig that referenced this pull request Oct 5, 2026
Continuation of locky504's open PR synfig#3702 at head 242e652: pasting a nested skeleton no longer drops the inner structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant