narzoul / DDrawCompat

DirectDraw and Direct3D 1-7 compatibility, performance and visual enhancements for Windows Vista, 7, 8, 10 and 11
BSD Zero Clause License
969 stars 70 forks source link

TUC Command & Conquer and Red Alert black screen/freeze on first launch, but work fine afterwards #387

Open ReplicantKD637 opened 4 weeks ago

ReplicantKD637 commented 4 weeks ago

DDrawCompat-C&C95.log Hello, thanks for the wonderful wrapper.

I have the Ultimate Collection on Steam, which is bundled with your wrapper. No clue if the issue is on the game files or the wrapper, but I'll try to explain anyways.

So I boot my computer, try to launch Command & Conquer 95, resulting in a black screen and it freezes there, like it attempts to play the intro video but fails. I can close the process and then launch the game again, at which point the game works perfectly, and so does RA1. I have to do this on every boot/restart of my PC.

This only happens with C&C95 and RA1.

I also have Dune 2000, which is not on Steam and it works perfectly with your wrapper.

I'm running Windows 11 Pro 24H2, 12gen Intel CPU and NVIDIA GPU.

narzoul commented 4 weeks ago

Same issue and same solution as here: #372

I've been working on a different approach to implement the CpuAffinty setting, by setting individual thread affinities instead of the whole process affinity at once. My original intent was to allow certain threads to be excluded from the affinity restriction, such as DDrawCompat's own helper threads. But interestingly, with this approach, even if I restrict every single thread to a single core, it still avoids this strange bug on Windows 11 24H2. I don't know what is going on anymore.

You can either use CpuAffinity=all, or you can try the new CpuAffinity approach with this: ddraw.zip (diff.txt compared to v0.5.4)

Note that the above patch already removes the CpuAffinity restriction for DDrawCompat's threads, driver threads (for DLLs under DriverStore), DirectSound and DirectInput. Although this doesn't seem necessary to fix this current issue, it might still improve performance overall when using single core affinity.

narzoul commented 4 weeks ago

Trying to debug the problem a little further, the only thing I could determine is that it must be related to audio somehow. After disabling all audio devices on my system (through Device Manager) and restarting my PC, I can no longer reproduce the freezes on startup. The game will complain about some DirectSound issue in a popup message, but after dismissing that, it will get to the main menu without sound fine. However, the game will instead freeze when exiting from the main menu, but that might be an altogether different bug in the game.

I'm not entirely sure if the issue is with DirectSound itself, or the way the game uses it, but every time I break into it with a debugger while it's frozen, the main thread is busy in some DirectSound method (usually some internal function called GetCurrentPosition). Using an older dsound.dll doesn't help, but the issue definitely wasn't present on 23H2.

Sometimes some dsound.dll threads are also in questionable state, like stuck in a LoadLibraryExA call trying to load avrt.dll, but bypassing that call doesn't solve the issue. Maybe someone with more experience with DirectSound could debug it further.

Anyway, this is rather off topic for DDrawCompat, and I'm quite content with the patch above for now.

ReplicantKD637 commented 4 weeks ago

Thank you for the insight. Using Cpuaffinity=all worked wonders, I didn't notice anything going wrong so far (at least in C&C95).