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

Misuse of IM_ASSERT_USER_ERROR #593

Open
ocornut opened this issue Sep 23, 2024 · 1 comment
Open

Misuse of IM_ASSERT_USER_ERROR #593

ocornut opened this issue Sep 23, 2024 · 1 comment

Comments

@ocornut
Copy link
Collaborator

ocornut commented Sep 23, 2024

IM_ASSERT_USER_ERROR() was designed to specifically cover errors that are safely recoverable.
So e.g.

IM_ASSERT_USER_ERROR(gp.CurrentPlot != nullptr && !gp.CurrentPlot->SetupLocked,
                     "Setup needs to be called after BeginPlot and before any setup locking functions (e.g. PlotX)!");    // get plot and axis
ImPlotPlot& plot = *gp.CurrentPlot;

The gp.CurrentPlot != nullptr part of it is incorrect.

I suggest not to take action right now as I am in the process of reworking this system to provide new error handling mechanisms.
I will try to post some update here eventually, but felt it was safer to leave the info down here.

@ocornut
Copy link
Collaborator Author

ocornut commented Sep 27, 2024

Pushed better error recovery support to imgui master:
ocornut/imgui#1651 (comment)

Calling IM_ASSERT_USER_ERROR() followed by a crash (e.g. in the case gp.CurrentPlot == NULL in my example above) is a little misleading, but not more damaging than an assert. Ideally the idea is that IM_ASSERT_USER_ERROR() should be in path where your code won't crash. I recommend only using it in entry points. Aka don't spam codebase with random calls to this in all leaf functions, but be considerate of what can the user errors cases be.

ImGui::Begin("....");
[00001] [imgui-error] (current settings: Assert=1, Log=1, Tooltip=1)
[00001] [imgui-error] In window 'Oops!': Missing End()
Assertion failed: (0) && "Missing End()", file c:\omar\work\imgui\imgui.cpp, line 10501

image

image

I started working on a new https://github.com/ocornut/imgui/wiki/Error-Handling page too.

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

1 participant