IMGUI_DISABLE_OBSOLETE_FUNCTIONS affects layout of ImGuiIO #1695

Closed
opened 2018-03-24 23:46:35 +00:00 by zx64 · 5 comments
zx64 commented 2018-03-24 23:46:35 +00:00 (Migrated from github.com)

This issue is more a heads up for anyone else that might run into this because of project build settings etc.

Example symptom: reading io.MouseWheel etc. in your code stays zero despite it scrolling windows, showing up as non-zero in the demo window etc.

The cause is inconsistently defining IMGUI_DISABLE_OBSOLETE_FUNCTIONS throughout your project, which means some (but not all) member accesses after the RenderDrawListsFn function pointer will be the incorrect offset.

This can be verified by looking at the disassembly of an affected function: devenv

Entirely my fault of course, hopefully nobody else runs into this! (Equally, hopefully there's enough keywords for someone to find this if it does happen to them)

This issue is more a heads up for anyone else that might run into this because of project build settings etc. Example symptom: reading `io.MouseWheel` etc. in your code stays zero despite it scrolling windows, showing up as non-zero in the demo window etc. The cause is inconsistently defining `IMGUI_DISABLE_OBSOLETE_FUNCTIONS` throughout your project, which means some (but not all) member accesses after the `RenderDrawListsFn` function pointer will be the incorrect offset. This can be verified by looking at the disassembly of an affected function: ![devenv](https://i.gyazo.com/8d53faaee2f3d6a0afbbe1f29827b24e.png) Entirely my fault of course, hopefully nobody else runs into this! (Equally, hopefully there's enough keywords for someone to find this if it does happen to them)
franciscod commented 2018-04-22 21:31:14 +00:00 (Migrated from github.com)

Just got bitten by this. Thanks for the heads-up!

Just got bitten by this. Thanks for the heads-up!
ocornut commented 2018-04-22 21:38:29 +00:00 (Migrated from github.com)

@zx64 @franciscod May I ask you both how/where did you try to put those define?
The documentation states in multiple place that they need to be in imconfig.h for that reason. I now have added some extra commentary last month as you can see in the commit above.

I'm just trying to understand why/how you got it wrong so I can find way to reduce the likehood it happens to other people. Perhaps need to add a mechanism that requires passing sizeof(ImGuiIO) etc. to the cpp file so the value from different compilation unit can be compared.

@zx64 @franciscod May I ask you both how/where did you try to put those define? The documentation states in multiple place that they need to be in imconfig.h for that reason. I now have added some extra commentary last month as you can see in the commit above. I'm just trying to understand why/how you got it wrong so I can find way to reduce the likehood it happens to other people. Perhaps need to add a mechanism that requires passing sizeof(ImGuiIO) etc. to the cpp file so the value from different compilation unit can be compared.
franciscod commented 2018-04-22 22:12:31 +00:00 (Migrated from github.com)

I had this line:

#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS

on my imgui_user_config.h, but wasn't consistently passing the
-DIM_USER_CONFIG="path/imgui_user_config.h"
to all build steps (and I'm not including that header anywhere by hand). So
ImGui had it defined but my code didn't, or viceversa. I refactored my
Makefile a bit and added $(PWD) to the path to make it absolute to be sure
it's pointing to the right place.

I had this line: #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS on my imgui_user_config.h, but wasn't consistently passing the -DIM_USER_CONFIG="path/imgui_user_config.h" to all build steps (and I'm not including that header anywhere by hand). So ImGui had it defined but my code didn't, or viceversa. I refactored my Makefile a bit and added $(PWD) to the path to make it absolute to be sure it's pointing to the right place.
ocornut commented 2018-04-25 20:16:56 +00:00 (Migrated from github.com)

I have added a macrio IMGUI_CHECKVERSION() which checks the size of data structures which are mostly likely to be affected by mismatching compilation settings or mismatching configuration option.

All the examples are now calling IMGUI_CHECKVERSION() in their main.cpp code, which hopefully means that new users will adopt it naturally in their own codebase. Also added a comment about it in imconfig.h so hopefully more people will see it.

Closing this.

I have added a macrio `IMGUI_CHECKVERSION()` which checks the size of data structures which are mostly likely to be affected by mismatching compilation settings or mismatching configuration option. All the examples are now calling IMGUI_CHECKVERSION() in their main.cpp code, which hopefully means that new users will adopt it naturally in their own codebase. Also added a comment about it in `imconfig.h` so hopefully more people will see it. Closing this.
franciscod commented 2018-04-26 19:12:49 +00:00 (Migrated from github.com)

Nice idea! Thanks!

Nice idea! Thanks!
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#1695
No description provided.