Skip to content
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

IDWriteTextRenderer::DrawGlyphRun takes &self and *const c_void. No pointer to mutable state present. #3002

Closed
david7a68 opened this issue Apr 18, 2024 · 3 comments
Labels
question Further information is requested

Comments

@david7a68
Copy link

Summary

When implementing IDWriteTextRenderer, it makes sense that one would need mutable state somewhere, if only to record glyphs. However, the function signature for IDWriteTextRenderer::DrawGlyphRun does not allow mutable access to self or the context pointer.

This doesn't prevent an implementation from working, but it certainly is an ergonomic papercut.

Crate manifest

windows-core = "0.56"

[dependencies.windows]
version = "0.56"
features = [
    "implement",
    "Win32_Graphics_Direct2D_Common",
    "Win32_Graphics_DirectWrite",
    "Win32_System_Com",
]

Crate code

No response

@david7a68 david7a68 added the bug Something isn't working label Apr 18, 2024
@kennykerr kennykerr added question Further information is requested and removed bug Something isn't working labels Apr 18, 2024
@riverar
Copy link
Collaborator

riverar commented Apr 18, 2024

If I understood correctly, you're implementing an interface; &mut self isn't possible with COM where references can linger around. Instead, try using something like RefCellor RwLock to coordinate access to mutable state.

Some examples:

@kennykerr
Copy link
Collaborator

Right, &mut self implies exclusive access which is not compatible with COM where you may have multiple references accessing the same object simultaneously. Using &self forces you to be deliberate about this and avoids undefined behavior.

@david7a68
Copy link
Author

I see. Closing this issue.

Thanks for the clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants