Skip to content

How to put MTLTexture into ImGuiImage from dictionary? #25

@tanelxen

Description

@tanelxen

That question mainly about pointers management in Swift than SwiftImGui as is.

I'm trying to add thumbnail in asset browser, but get bad access because pointer to texture isn't valid at the moment when ImGuiImage have to be rendered.

I hold textures for thumbnails in dictionary and render it like this:

var textures: [String: MTLTexture]
....
let ptr = withUnsafePointer(to: &textures[name]) { ptr in
    return UnsafeMutableRawPointer(mutating: ptr)
}

ImGuiImage(
    ptr,
    ImVec2(24, 24),
    ImVec2(0, 0),
    ImVec2(1, 1),
    ImVec4(1, 1, 1, 1),
    ImVec4(1, 1, 1, 1)
)

It would be nice to use ids instead of pointers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions