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

Compiler warning about printing ImTextureID #2548

Closed
eliasdaler opened this issue May 11, 2019 · 4 comments
Closed

Compiler warning about printing ImTextureID #2548

eliasdaler opened this issue May 11, 2019 · 4 comments

Comments

@eliasdaler
Copy link
Contributor

eliasdaler commented May 11, 2019

Hello, I've ignored this warning for quite some time, but I think that it's easy to deal with, but needs some discussion. Basically, it's this:

imgui.cpp:9626:245: warning: format specifies type 'void ' but the argument has type 'unsigned int' [-Wformat]
bool pcmd_node_open = ImGui::TreeNode((void
)(pcmd - draw_list->CmdBuffer.begin()), "Draw %4d %s vtx, tex 0x%p, clip_rect (%4.0f,%4.0f)-(%4.0f,%4.0f)", pcmd->ElemCount, draw_list->IdxBuffer.Size > 0 ? "indexed" : "non-indexed", pcmd->TextureId, pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w);

Here, the problem is that ImTextureID is assumed to be void*, but in custom bindings another type may be used. In ImGui-SFML, it's unsigned int.

So, the way to deal with this is to make "0x%p" part of this format string modifiable. We can have something like ImTextureIDPrintSpecifier to allow bindings to define how ImTextureID should be printed. It can be "0x%p" by default, same as ImTextureID is void* by default.

Thoughts?

@ocornut
Copy link
Owner

ocornut commented May 11, 2019

Can't we just cast the value at the printf call site?

@eliasdaler
Copy link
Contributor Author

eliasdaler commented May 11, 2019

We can, but we'll get something like "0x5", as if it was address, instead of just "5". (ImTextureID in ImGui-SFML is OpenGL's texture handle).

But yeah, it's better than nothing. :)

@ocornut
Copy link
Owner

ocornut commented May 11, 2019

This is fine. This printout is merely a debugging/auditing tool, if we wanted to decorate this properly we'd need higher level primitives (e.g. query texture name from id).

0x5 is hexadecimal, it doesn't mean it is an address.

@ocornut ocornut closed this as completed May 11, 2019
@eliasdaler
Copy link
Contributor Author

Okay, thanks!

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

No branches or pull requests

2 participants