-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom attachments #20
Conversation
I am working on the interface to modify a region attachment after it has been created. The region attachment can be empty upon creation, but to render any visible contents, the user needs to set all fields and call update_region. This should be clear and not something you can mess up. |
spSlot_setAttachment: It appears that setting the attachment on the slot does not increment the attachment ref count. This seems strange to me, as the pointer is in use and if an attachment is set on a skin the ref count is incremented. It seems to me that an attachment that is in use by a slot should have its refcount increment and dispose called when it is no longer in use, but spine c does not do this. As a result, it is possible to set an attachment on a slot and then drop the attachment, causing an access violation. |
Another issue I am investigating is that calling Slot::set_attachment cause an immediate panic. Calling the underlying c::spSlot_setAttachment works fine. Edit: This is due to the non-incrementing ref count. If the refcount is incremented by spSlot_setAttachment, Slot::set_attachment is reliable. |
An alternative to making attachment accessors mutable is to place the create attachment convenience function in RegionAttachment and have it take the loader and props as arguments. |
Example of the current code: let attachment_loader = AttachmentLoader::new_atlas_loader(&atlas);
let region_props = RegionProps {
x: 0.0,
y: 0.0,
scale_x: 1.0,
scale_y: 1.0,
rotation: 0.0,
width: 128.0,
height: 128.0,
color: Color::new_rgba(1.0, 1.0, 1.0, 1.0),
};
let attachment = attachment_loader
.create_region_attachment(None, "test", "head", ®ion_props)
.unwrap();
unsafe {
let mut slot = controller.skeleton.find_slot_mut("front-shin").unwrap();
slot.set_attachment(Some(attachment.clone()));
} |
Nice work.
We shouldn't be making modifications directly to |
src/c_interface.rs
Outdated
|
||
$(#[$($attrss)*])* | ||
pub fn $rust_set(&mut self, value: String) { | ||
let c_str = std::ffi::CString::new(value).expect("Null byte found in provided string"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize it's an exceedingly rare case, but I think we should bubble up the error here, wrapped in SpineError::NulError
.
src/attachment_loader.rs
Outdated
/// # Errors | ||
/// | ||
/// Returns [`AttachmentLoaderError::CreateAttachmentFailed`] if creating the attachment failed. | ||
/// Check error1() and error2() for more information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Check error1() and error2() for more information. | |
/// Check [`error1`](`Self::error1`) and [`error2`](`Self::error2`) for more information. |
Yeah, that's why I noted this is temporary. The goal of this was to prove out it resolves the problems, which it does in my testing. |
As far as I can tell, this is safe to do if the attachment is valid, once esoteric updates spine with the ref count increment in spSlot_setAttachment
This is all usable. Anything else I should do here? It doesn't require any changes from the spine runtime. |
Ship it! |
In progress PR adding the ability to create custom attachments that can be assigned to slots.
May optionally include the ability to create custom attachment loaders.