Holy shit I hate headers
Posted: November 26th, 2017, 10:06 pm
So I've been trying to setup a D3D framework for a few days now and was running into some compile errors. These errors were coming from WinNT.h and IntSafe.h, which are part of the Windows SDK so I knew they weren't really the issue. I've had issues in the past with including Windows.h out of order from say Winsock2.h, and I've had errors trying to bypass including Windows.h by just including WinUser.h or something to cut back on the amount of included files. This wasn't the case this time. I had a chili like include file defining WIN32_LEAN_AND_MEAN and NOMINMAX, then including Windows.h, d3d11.h, wincodec.h and wrl/client.h. I did this so the defined macros would propagate through the loading of Direct3D and the Windows Imaging Component headers since they both include Windows.h.
The rest of the solution had a Model class and a Camera class that needed the DirectX math and DirectX collision headers ( DirectXMath.h and DirectXCollision.h ) and I made some helper classes and functions for extending the functionality of the DirectX math types ( XMFLOAT3, XMFLOAT4X4, etc... ). These were in a Math.h file that included cmath and DirectXMath.h. This file was included by Camera.h and Model.h. They both also had #include <DirectXCollision.h> in them.
So after spending the last couple of days looking for inclusions of Windows headers out of order, I decided I'd exclude all files from the project and add them back one by one until I found the trouble maker(s). Everything went well until I came to Camera.h. Including that file, which included Model.h caused the errors. So I commented out #include "Model.h" and it compiled fine. I followed the includes between Camera and Model and there wasn't any Windows headers in the hierarchy of included headers...unless you could the DirectXMath and DirectXCollision headers. And there it was.
I had in one of the files included DirectXCollision before DirectXMath and it may have been more indirect than that. If I remember correctly, I included the DirectXCollision header in Model and Camera, and the DirectXMath header in Math.h. Which meant somewhere down the line, DirectXCollision was included before DirectXMath. The solution was rearrange the damn #include statements so that headers were included in the correct order.
TL;DR Headers suck and hope modules helps this BS nightmare of inclusion order.
The rest of the solution had a Model class and a Camera class that needed the DirectX math and DirectX collision headers ( DirectXMath.h and DirectXCollision.h ) and I made some helper classes and functions for extending the functionality of the DirectX math types ( XMFLOAT3, XMFLOAT4X4, etc... ). These were in a Math.h file that included cmath and DirectXMath.h. This file was included by Camera.h and Model.h. They both also had #include <DirectXCollision.h> in them.
So after spending the last couple of days looking for inclusions of Windows headers out of order, I decided I'd exclude all files from the project and add them back one by one until I found the trouble maker(s). Everything went well until I came to Camera.h. Including that file, which included Model.h caused the errors. So I commented out #include "Model.h" and it compiled fine. I followed the includes between Camera and Model and there wasn't any Windows headers in the hierarchy of included headers...unless you could the DirectXMath and DirectXCollision headers. And there it was.
I had in one of the files included DirectXCollision before DirectXMath and it may have been more indirect than that. If I remember correctly, I included the DirectXCollision header in Model and Camera, and the DirectXMath header in Math.h. Which meant somewhere down the line, DirectXCollision was included before DirectXMath. The solution was rearrange the damn #include statements so that headers were included in the correct order.
TL;DR Headers suck and hope modules helps this BS nightmare of inclusion order.