Null reference crash #4562

Closed
opened 2021-09-20 15:09:05 +00:00 by BattleAxeVR · 3 comments
BattleAxeVR commented 2021-09-20 15:09:05 +00:00 (Migrated from github.com)

image

bd is null.

Happens 100% when I close my app.

Tired of having to add a null check after every merge so I figured I might as well report it.

Before anyone says "just define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD", no, that's not correct.

Libraries shouldn't crash on nullptrs.

Thanks!

![image](https://user-images.githubusercontent.com/11604039/134026107-d8d5f476-7961-4c75-a864-3fe5cc4461c2.png) bd is null. Happens 100% when I close my app. Tired of having to add a null check after every merge so I figured I might as well report it. Before anyone says "just define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD", no, that's not correct. Libraries shouldn't crash on nullptrs. Thanks!
PathogenDavid commented 2021-09-20 15:36:36 +00:00 (Migrated from github.com)

The backend data should not normally be null. It being null implies there's something else wrong with your app. (I won't dispute that it could be handled more gracefully, but IMO it should be an assert not a null check.)

Are you calling ImGui_ImplWin32_Shutdown without calling ImGui_ImplWin32_Init?

Are you calling ImGui_ImplWin32_Shutdown more than once?

Are you calling ImGui::DestroyContext before ImGui_ImplWin32_Shutdown?

Are you using ImGui::SetCurrentContext?

Are you building Dear ImGui (or the backend) as a shared library/DLL?

The backend data should not normally be null. It being null implies there's something else wrong with your app. (I won't dispute that it could be handled more gracefully, but IMO it should be an assert not a null check.) Are you calling `ImGui_ImplWin32_Shutdown` without calling `ImGui_ImplWin32_Init`? Are you calling `ImGui_ImplWin32_Shutdown` more than once? Are you calling `ImGui::DestroyContext` before `ImGui_ImplWin32_Shutdown`? Are you using `ImGui::SetCurrentContext`? Are you building Dear ImGui (or the backend) as a shared library/DLL?
BattleAxeVR commented 2021-09-20 15:54:26 +00:00 (Migrated from github.com)

Ahh, I just checked and I was calling my shutdown sequence twice, good catch. Still, it's good to add a null check anyway.

Ahh, I just checked and I was calling my shutdown sequence twice, good catch. Still, it's good to add a null check anyway.
ocornut commented 2021-09-20 16:46:30 +00:00 (Migrated from github.com)

Pushed c6ca327fb2 with more explicit asserts.

We are a low-level library and frequently crash on NULL pointers (rather than adding redundant asserts at the same location where the crash would happen), but on "key" functions like this I agree it makes sense to add an explicit assertion.

Pushed c6ca327fb2c4a0bb35b92a1ca8633991379463df with more explicit asserts. We are a low-level library and frequently crash on NULL pointers (rather than adding redundant asserts at the same location where the crash would happen), but on "key" functions like this I agree it makes sense to add an explicit assertion.
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#4562
No description provided.