evilrat666 / directx-d

[DISCONTINUED] DirectX bindings for D
MIT License
20 stars 16 forks source link

DrawTextLayout only works 50% of the time #12

Open fourst4r opened 2 years ago

fourst4r commented 2 years ago

When you run this app you have about a 50% chance to see the text rendered using DrawTextLayout lol, I'm so lost, this is a hideous bug. Works every time with DrawText though.

D code: https://gist.github.com/fourst4r/1a16587608bdacd6aad22cf170426269

Translated from a sample here https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/multimedia/DirectWrite/HelloWorld/MultiformattedText.cpp

fourst4r commented 2 years ago

Actually there's a much rarer third variation of the bug which just moves the text off the side of the screen. Here is three variations of launching the same exe file >image If anyone knows anything I would be eternally grateful.

evilrat666 commented 2 years ago

Sorry I'm a bit busy to check myself but here are some possible causes:

Recently there was added more stuff to the API that haven't been updated in this repo.

Some structures may be expanded in that time, but their bindings counterparts are not, which means it might have wrong data that causes such functions to silently fail.

Given that it only fails sometimes and sometimes it works might indicate that's the case, additionally it could be that somewhere in structs or parameters float NaN (default in D for floating point numbers) is passed which causes a lot of PITA dealing with C/C++ where NaN's are rarely handled. So in the end it works by accident where struct config overlaps with some random garbage in memory that got discarded by internal checks and rewritten as defaults internally.

And lastly - expanded API caused off-by-one error where for example function call landed up on DoStuffExtra in vtable instead of plain DoStuff that differs only in extra added parameter(s) that picks up garbage on call and that works (no crash) just by accident.

Edit: this struct initialization syntax is one possible place where the rest of the members initialized to what DirectX doesn't expect https://gist.github.com/fourst4r/1a16587608bdacd6aad22cf170426269#file-multiformattedtext-d-L307