Skip to content

Instantly share code, notes, and snippets.

@CookiePLMonster
Created August 2, 2019 16:38
Show Gist options
  • Save CookiePLMonster/18632c532d510ddcf5fbb1c84fad672a to your computer and use it in GitHub Desktop.
Save CookiePLMonster/18632c532d510ddcf5fbb1c84fad672a to your computer and use it in GitHub Desktop.
Windows 10 dinput8.dll premature deinitialization bug
// Simple test program for Windows 10's dinput8.dll premature deinitialization bug
// Adrian Zdanowicz (Silent), 2019
// This basic program showcases an issue with how dinput8 queues a work item in its own DllMain.
// The issue comes from a fact that unloading dinput8 does not wait for this work item to finish,
// so if it's not quick enough, DLL will get unloaded while a thread pool still executes this work item.
// To observe the crash:
// - With a ready executable, add it to Application Verifier.
// - Uncheck all tests excepts Basic -> Threadpool test and save changes.
// - Launch the executable.
// - Observe it closes.
// So far this issue has been identified with Windows 10 1803, 1809 and 1903.
#include <Windows.h>
int main()
{
// To keep the sample straightforward, assume LoadLibrary succeeds
FreeLibrary(LoadLibrary(TEXT("dinput8")));
for ( ;; ) Sleep(1); // Just wait for the crash now!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment