@hwnd%

Discussions related to graphics (2D and 3D), animation and games programming
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Wed 11 Mar 2026, 22:16 I assume then that all the structures need to be treated this way.
If you specifically mean padding at the end, obviously that only makes a difference when it's used as a sub-structure within a parent structure, otherwise it has no effect (other than to waste memory).

But generally alignment within structures matters, just as it does in 32-bits. Moving to 64-bits doesn't alter the requirement to align structure members, but of course that alignment will typically be different (commonly 8 bytes rather than 4).
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Thanks for the clarification
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I am sorry to report that it sill fails to load the swapchain, I have run out of ideas as to what the problem could be, is there anything else you think might be the problem?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Thu 12 Mar 2026, 18:45 I have run out of ideas as to what the problem could be
Doesn't the mode of failure point in a particular direction? If it's crashing, make sure you've installed a Postmortem Debugger as I advised earlier, so you can see exactly what is causing the crash. If it's not crashing, add loads of diagnostic PRINT statements so you can check for anything giving an unexpected result. Have you investigated the Direct3D 11 Debug Layer?
is there anything else you think might be the problem?
Did you forget to include the MRE? There's nothing for me to try here!
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I will have a look at the diagnostic, I posted the smallest amount of code I could a few posts ago. I'm not sure it can be made any smaller and still contain enough code to initiate the swapchain.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

As far as I understand, the debug layer is used to diagnose faults once you have created the device. The code currently fails before the device is created. 😱
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Thu 12 Mar 2026, 19:48 I posted the smallest amount of code I could a few posts ago.
That code ran OK here, in 64-bit BBCSDL, although admittedly when I try it again today it doesn't! So it looks as though there's some variability between runs that needs to be investigated. Not the nicest kind of issue to debug, admittedly. :(
As far as I understand, the debug layer is used to diagnose faults once you have created the device.
I don't see why you shouldn't use it when you (attempt to) create the device. If I try that here, it returns the error "0x887a002d: The application requested an operation that depends on an SDK component that is missing or mismatched" which is not surprising because I don't have the SDK installed.

Assuming you do (or you install it specifically for the purpose) it may be that the Debug Layer will provide some valuable information. You've got nothing to lose by trying it, anyway.
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Richard Russell wrote: Thu 12 Mar 2026, 09:21 But generally alignment within structures matters, just as it does in 32-bits. Moving to 64-bits doesn't alter the requirement to align structure members, but of course that alignment will typically be different (commonly 8 bytes rather than 4).
I found the issue, and it was indeed one of alignment. I had expected that the DXGI_MODE_DESC structure would need to be padded to a multiple of 8 bytes, but it turns out that with the particular structure packing method used in this case it doesn't, so you must remove the Padding% member I added.

But of course now, with the DXGI_MODE_DESC structure no longer a multiple of 8-bytes long, this throws out the alignment of the subsequent members of the DXGI_SWAP_CHAIN_DESC structure. So you must insert 4 bytes of padding before the OutputWindow%% member to restore it.

With those two changes (in effect one change: moving Padding% from one place to another) it works consistently here. I'm not too sure why it worked for me the other day, but I'm sure it did.

The unfortunate thing is that without carefully studying the header files uses by Microsoft you don't know what packing option was used by the C compiler, so you don't know exactly what you need to do in BBC BASIC to match it.
Ric
Posts: 297
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Thank you so much, could I ask where you looked to find the information, I asked meta AI to give me the byte sizes of all the structures and I put the corresponding variables in to the corresponding slots. You mention the c compiler used by ms?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 634
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Fri 13 Mar 2026, 08:20 Thank you so much, could I ask where you looked to find the information, I asked meta AI to give me the byte sizes of all the structures
I used Gemini AI (Google), but yes asking for the byte sizes of the structures is exactly what I did.

You do need to be careful because even the best LLM chatbots are still not good at counting, because they only understand 'tokens' (basically words) internally. I had to correct Gemini for telling me that "mysql_native_password" and "caching_sha2_password" had different numbers of characters, when in fact they are the same length!

I have in the past resorted to writing a trivial C program which would tell me the size of a structure. Something like this:

Code: Select all

#include <dxgi.h>
int main(int argc, char* argv[])
    {
	printf ("Size of DXGI_SWAP_CHAIN_DESC is %d bytes\n", sizeof(DXGI_SWAP_CHAIN_DESC));
	return 0;
    }
That should be trustworthy, although rarely you can get differences depending on which compiler you use (e.g. MSVC versus GCC).