From d80a51cd12b3af74084d63e949546c5587d851c1 Mon Sep 17 00:00:00 2001 From: gucio321 <73652197+gucio321@users.noreply.github.com> Date: Tue, 17 Sep 2024 20:28:11 +0200 Subject: [PATCH] examples/dragdrop: fix crash There were 3 problems: - call to SetDragDropPayload declared data_size always as 0 - null chceck in DragDropTarget checked only if returned payload isn't nil but didn't if CData isn't (cimgui-go changs - generally should be fixed in cimgui-go somehow) - there was also a small issue in result decoding as the label presented pointer address and not its value resolve #832 --- examples/dragdrop/dragdrop.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/dragdrop/dragdrop.go b/examples/dragdrop/dragdrop.go index cc4f056b..bf75dc4d 100644 --- a/examples/dragdrop/dragdrop.go +++ b/examples/dragdrop/dragdrop.go @@ -16,11 +16,11 @@ func loop() { g.Custom(func() { g.Button("Drag me: 9").Build() if imgui.BeginDragDropSource() { - data := 9 + data := int(9) imgui.SetDragDropPayload( "DND_DEMO", uintptr(unsafe.Pointer(&data)), - 0, + uint64(unsafe.Sizeof(data)), ) g.Label("9").Build() imgui.EndDragDropSource() @@ -33,7 +33,7 @@ func loop() { imgui.SetDragDropPayload( "DND_DEMO", uintptr(unsafe.Pointer(&data)), - 0, + uint64(unsafe.Sizeof(data)), ) g.Label("10").Build() imgui.EndDragDropSource() @@ -44,8 +44,8 @@ func loop() { g.Custom(func() { if imgui.BeginDragDropTarget() { payload := imgui.AcceptDragDropPayload("DND_DEMO") - if payload != nil { - dropTarget = fmt.Sprintf("Dropped value: %d", payload.Data()) + if payload != nil && payload.CData != nil { + dropTarget = fmt.Sprintf("Dropped value: %d", *(*int)(unsafe.Pointer(payload.Data()))) } imgui.EndDragDropTarget() }