HW3D exception throwing thing

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
AleksiyCODE
Posts: 14
Joined: September 21st, 2019, 8:47 pm

HW3D exception throwing thing

Post by AleksiyCODE » December 2nd, 2019, 7:29 pm

So i finally mustered the courage to start rebasing my game to the latest Chili engine. While grinding through the tutorials i slowly incorporated the basics of Graphics class, main window and exception throwing, etc. After all compile errors were gone everything seemed to work, untill Chili sugested (https://youtu.be/HKMLUL3dMM0?t=399 timecode) to test exception throwing. I did the same, but the program just crashed in debug mode (no matter if you just run or use the debugger). Then i decided to try it on current framework version (Tutorial 39) and it also crashed without any popup. Stepping through the programm showed that it crashes on these lines in HandleMsg function in Window.cpp
"if( ImGui_ImplWin32_WndProcHandler( hWnd,msg,wParam,lParam ) )
{
return true;
}
const auto& imio = ImGui::GetIO();"
I can see what the problem is, but
1)dont really know how to fix it.
2)does it even need fixing?
I like ass

albinopapa
Posts: 3930
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: HW3D exception throwing thing

Post by albinopapa » December 3rd, 2019, 12:11 am

When you say it crashes without popup, what does it do?
Does your WinMain function have a try/catch block?

It would be easier to help if we had a link to a git repo or a zipped archive of your version of the code.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
AleksiyCODE
Posts: 14
Joined: September 21st, 2019, 8:47 pm

Re: HW3D exception throwing thing

Post by AleksiyCODE » December 3rd, 2019, 4:13 pm

Thats the thing! You can use HW3D latest official tutorial version and it just quits th you break the window handle (just like in that video), because right after the exception is caught, the programm steps into HandleMsgThunk, that than calls HandleMsg, that than tries to execute "const auto& imio = ImGui::GetIO();" this line, but fails and crashes immidiately.
You cat try my version (commit - instacrash) https://gitlab.com/AleksiyCODE/riftedtimes
I like ass

User avatar
AleksiyCODE
Posts: 14
Joined: September 21st, 2019, 8:47 pm

Re: HW3D exception throwing thing

Post by AleksiyCODE » December 3rd, 2019, 4:14 pm

I dont really care as far as my own project goes, but it might not be good for the Framework
(or it is just a small little bullshit, that we dont have to worry about)
I like ass

albinopapa
Posts: 3930
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: HW3D exception throwing thing

Post by albinopapa » December 4th, 2019, 4:55 am

Mine didn't crash at all, I got a screen with WASD on it and nothing happened for a while, then it closed.

I didn't see anything referencing Imgui anywhere.

I'm probably not on the correct branch though.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 3930
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: HW3D exception throwing thing

Post by albinopapa » December 4th, 2019, 5:23 am

Okay, I think I found part of your problem.

For one, you have two Graphics classes, Graphics and DXGraphics, I don't think this is going to work the way you want it to.

Second, in DXGraphics::DXGraphics you have
sd.OutputWindow = (HWND)69;
which is part of the code to get the program to throw an exception and test the DXGIInfo class in the tutorials. When it does throw, the ImGui class is destroyed and then for some reason when it tries to show the MessageBox to display the error message, it goes into the message handler. This ends up calling into the ImGui message handler and an assert is triggered:
IM_ASSERT(GImGui != NULL && "No current context. Did you call ImGui::CreateContext() or ImGui::SetCurrentContext()?");
Instead of displaying an error popup window on the assert, it just crashes.

The window not showing up is annoying and I'm not sure why it's not showing up for both the exception and for the assertion failure.

The assert is from the: ImGuiIO& ImGui::GetIO() function and that should only be called while ImGui is active and initialized.

That's about all the information I gathered.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
AleksiyCODE
Posts: 14
Joined: September 21st, 2019, 8:47 pm

Re: HW3D exception throwing thing

Post by AleksiyCODE » December 5th, 2019, 5:42 pm

About 2 Graphics classes: i dont expect them to work together (because they draw to different buffers and only one can be presented to the screen (what i did not expect is when i left both EndFrame() function active, instead of only seing the screen, rendered by the Graphics class that posseses the latest called EndFrame(), my screen was flashing rapidly (probably each frame) swaping between two buffers. Have no idea why it is so, but thats ok)).

Now about exception. The message that gets into the Handler is 134 - that is WM_NCACTIVATE. I suppose it is sent because popup window takes fokus. But i was truly amazed that after (guess what) commenting out a
private: ImguiManager imgui;
variable stored in Game class, assertion triggered properly... This behaviour is m-f incomperhansable.

Events are like this (i think)
1)ImguiManager constructor called
2)exception thrown
3)ImguiManager destructor called
4)exception caught
5)assertion trigered

Why does removing steps 1 and 3 fixes the crash?

1)Im really curious why that happens
2)i have no idea at all why that happens (apart from the fact that Imgui might have fucked something up (ofc it's not Chili or me))
3)this really seems to be not worth the investigation
I like ass

albinopapa
Posts: 3930
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: HW3D exception throwing thing

Post by albinopapa » December 6th, 2019, 1:50 am

So, I think that assert is designed to throw an exception, but since you are already in the middle of an exception, the program calls abort() or terminate() which bypasses any cleanup and just exits the program.

Since the message handler is called and ImGui is still trying to access information inside the message handler: ImGui::GetIO() which throws an assertion because ImGui's destructor has already been called, I honestly don't know if that's a design flaw or not. You'd think if the MainWindow class unregisters the window from Windows, it wouldn't be trying to use MainWindow's message handler to create a system wide window.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
AleksiyCODE
Posts: 14
Joined: September 21st, 2019, 8:47 pm

Re: HW3D exception throwing thing

Post by AleksiyCODE » December 8th, 2019, 1:16 pm

Its weird, but the main window handles messages even after that exception was caught for as long as you dont press 'abort'. It does not happen when exception is thrown not from Graphics constructor, but from game.go() for example.

I think I've got this. The reason the Window class is not unregistered is because Window is a member of Game, and scince Graphics is also a member of Game when an exception is thrown from inside of Game constructor (from Graphics constructor in our case) the Game object is not considered fully constructed and thus the destructor is never callsed -> the window class never gets unregistered :MonsieurD:

I wont solve this problem now, but if some time in the future it hinders my existence, i will not hold back -.-
I like ass

albinopapa
Posts: 3930
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: HW3D exception throwing thing

Post by albinopapa » December 8th, 2019, 5:04 pm

Seems legit.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply