mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[flutter] Fix crashes & drawing.
This commit is contained in:
parent
45d9c0ede8
commit
4a661aedfb
@ -39,7 +39,7 @@ class _SpineWidgetState extends State<SpineWidget> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (skeletonDrawable != null) {
|
if (skeletonDrawable != null) {
|
||||||
print("Skeleton loaded, creating painter");
|
print("Skeleton loaded, rebuilding painter");
|
||||||
return CustomPaint(
|
return CustomPaint(
|
||||||
painter: _SpinePainter(this),
|
painter: _SpinePainter(this),
|
||||||
child: Container()
|
child: Container()
|
||||||
@ -62,11 +62,15 @@ class _SpinePainter extends CustomPainter {
|
|||||||
final drawable = state.skeletonDrawable;
|
final drawable = state.skeletonDrawable;
|
||||||
if (drawable == null) return;
|
if (drawable == null) return;
|
||||||
final commands = drawable.render();
|
final commands = drawable.render();
|
||||||
|
canvas.save();
|
||||||
canvas.translate(size.width / 2, size.height);
|
canvas.translate(size.width / 2, size.height);
|
||||||
for (final cmd in commands) {
|
for (final cmd in commands) {
|
||||||
canvas.drawVertices(cmd.vertices, BlendMode.srcOut, Paint()..color = Colors.white); //drawable.atlas.atlasPagePaints[cmd.atlasPageIndex]);
|
canvas.drawVertices(cmd.vertices, BlendMode.srcOut, drawable.atlas.atlasPagePaints[cmd.atlasPageIndex]);
|
||||||
}
|
}
|
||||||
canvas.drawLine(Offset(0, 0), Offset(size.width, size.height), Paint()..color = Colors.blue);
|
canvas.restore();
|
||||||
|
canvas.drawLine(Offset(0, 0), Offset(size.width, size.height), Paint()
|
||||||
|
..color = Colors.blue
|
||||||
|
..strokeWidth = 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -18,3 +18,6 @@ set_target_properties(spine_flutter PROPERTIES
|
|||||||
)
|
)
|
||||||
target_include_directories(spine_flutter PUBLIC spine-cpp/include)
|
target_include_directories(spine_flutter PUBLIC spine-cpp/include)
|
||||||
target_compile_definitions(spine_flutter PUBLIC DART_SHARED_LIB)
|
target_compile_definitions(spine_flutter PUBLIC DART_SHARED_LIB)
|
||||||
|
#target_compile_options(spine_flutter PUBLIC -fsanitize=address -fno-omit-frame-pointer)
|
||||||
|
#set_target_properties(spine_flutter PROPERTIES LINK_FLAGS -fsanitize=address)
|
||||||
|
|
||||||
|
|||||||
@ -97,8 +97,8 @@ FFI_PLUGIN_EXPORT void spine_skeleton_drawable_update(spine_skeleton_drawable *d
|
|||||||
|
|
||||||
spine_render_command *spine_render_command_create(int32_t numVertices, int32_t numIndices, spine_blend_mode blendMode, int pageIndex) {
|
spine_render_command *spine_render_command_create(int32_t numVertices, int32_t numIndices, spine_blend_mode blendMode, int pageIndex) {
|
||||||
spine_render_command *cmd = SpineExtension::alloc<spine_render_command>(1, __FILE__, __LINE__);
|
spine_render_command *cmd = SpineExtension::alloc<spine_render_command>(1, __FILE__, __LINE__);
|
||||||
cmd->positions = SpineExtension::alloc<float>(numVertices * 2, __FILE__, __LINE__);
|
cmd->positions = SpineExtension::alloc<float>(numVertices << 1, __FILE__, __LINE__);
|
||||||
cmd->uvs = SpineExtension::alloc<float>(numVertices * 2, __FILE__, __LINE__);
|
cmd->uvs = SpineExtension::alloc<float>(numVertices << 1, __FILE__, __LINE__);
|
||||||
cmd->colors = SpineExtension::alloc<int32_t>(numVertices, __FILE__, __LINE__);
|
cmd->colors = SpineExtension::alloc<int32_t>(numVertices, __FILE__, __LINE__);
|
||||||
cmd->numVertices = numVertices;
|
cmd->numVertices = numVertices;
|
||||||
cmd->indices = SpineExtension::alloc<uint16_t>(numIndices, __FILE__, __LINE__);
|
cmd->indices = SpineExtension::alloc<uint16_t>(numIndices, __FILE__, __LINE__);
|
||||||
@ -219,8 +219,8 @@ FFI_PLUGIN_EXPORT spine_render_command *spine_skeleton_drawable_render(spine_ske
|
|||||||
|
|
||||||
spine_render_command *cmd = spine_render_command_create(verticesCount, indicesCount, (spine_blend_mode)slot.getData().getBlendMode(), pageIndex);
|
spine_render_command *cmd = spine_render_command_create(verticesCount, indicesCount, (spine_blend_mode)slot.getData().getBlendMode(), pageIndex);
|
||||||
|
|
||||||
memcpy(cmd->positions, vertices->buffer(), (verticesCount << 2) * sizeof(float));
|
memcpy(cmd->positions, vertices->buffer(), (verticesCount << 1) * sizeof(float));
|
||||||
memcpy(cmd->uvs, uvs->buffer(), (verticesCount << 2) * sizeof(float));
|
memcpy(cmd->uvs, uvs->buffer(), (verticesCount << 1) * sizeof(float));
|
||||||
for (int ii = 0; ii < verticesCount; ii++) cmd->colors[ii] = color;
|
for (int ii = 0; ii < verticesCount; ii++) cmd->colors[ii] = color;
|
||||||
memcpy(cmd->indices, indices->buffer(), indices->size() * sizeof(uint16_t));
|
memcpy(cmd->indices, indices->buffer(), indices->size() * sizeof(uint16_t));
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user