narzoul / DDrawCompat

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

Bugs in Carnivores 1, 2 and Ice Age #320

Open raptor264 opened 1 month ago

raptor264 commented 1 month ago

It mostly presents errors in the landscape (terrain).

DDrawCompat-CARN2.log DDrawCompat-HuntD3D Carn1.log DDrawCompat-IceAge.log DDrawCompat-v_d3d.ren Carn2.log DDrawCompat-v_d3d.ren CarnIceAge.log

narzoul commented 1 month ago

I tested the first game briefly but didn't notice any graphical issues. Could you take a screenshot to show what it looks like?

What is your GPU model? Is it an integrated GPU?

raptor264 commented 1 month ago

How do I get that information? Doesn't it appear in the logs?. here is the screenshot.

image
narzoul commented 1 month ago

How do I get that information? Doesn't it appear in the logs?

I can only tell from the logs that it's some kind of AMD GPU.

In the Start menu, type dxdiag and press enter. Go to the Display tab and either take a screenshot of it, or press the "Save All Information..." button and upload the resulting text file.

here is the screenshot.

That's very strange. Does it appear correctly if you don't use DDrawCompat? Does the black pattern move as you move your character, or does it stay in the same location always?

narzoul commented 1 month ago

Also, what are your in-game videos settings? Have you tried turning off fog and shadows, or changing the other video settings to see if it fixes the problem?

Are there any mods or patches installed, besides the "Carnivores Direct3D patch (beta 1.5)"?

raptor264 commented 1 month ago
image

I turned off the shadows... and the error continues. Those graphical errors disappear as you walk through the game.

All the carnivores games I have have the latest official patch installed... Carnivores 1 has the beta 1.5 patch, I just confirmed it

narzoul commented 1 month ago

I tested 3 different GPUs (AMD, Intel and NVIDIA) and none of them have this issue. Yours seems to be an integrated AMD GPU. Unfortunately I can only test a dedicated one at the moment.

But I was finally able to reproduce it by using D3D9On12 instead of a native driver. With that, it can also be reproduced without using DDrawCompat, so at least it's not a bug in DDrawCompat itself. It must be some driver issue. Maybe I'll be able to figure it out now that I can reproduce it.

raptor264 commented 1 month ago

Ok, I'll be attentive to a possible fix.

narzoul commented 4 weeks ago

I found the issue, at least as far as D3D9On12 is concerned, but since the symptoms are the same, I assume it's the same issue as with your GPU.

The game uses texture sizes of 64x64, 128x128 and 256x256. The problem with D3D9on12 is that when a texture of size 64x64 is locked for CPU access, the surface pitch becomes the same as for textures of size 128x128. This makes the game not fill the texture with any data, so it remains pitch black.

It's simple enough to fix in DDrawCompat, since it already has optimizations to replace the usual surface lock mechanism by copying the surface between a system memory surface and the video memory surface. In this case, the game will see the pitch of the system memory surface, which always matches the expected pitch, irrespective of GPU drivers.

This optimization was so far not enabled for textures, as I thought it was unnecessary, and it might actually impair performance in some cases. But I enabled it for now in this patch: ddraw.zip (diff.txt compared to v0.5.2)

Now on to the bad news. This exposes another bug in the game. When you enter a hunt, it attempts to measure some "texture transfer speed", which is visible in carnivor.log. But with the above optimization enabled, this makes it look like texture transfer is almost instantaneous on fast CPUs, because it delays the actual upload of the texture data from system memory to video memory until the texture is actually referenced by a rendered triangle. This results in the texture transfer speed measurement pretty reliably crashing with an "integer division by zero" exception, as the game uses the timeGetTime Windows API function to measure the elapsed time in milliseconds, which will end up being zero.

There are at least two ways to get around the above crash. One is to use the Microsoft Application Compatibility Toolkit to enable the IgnoreException shim, with its command line parameter set to INT_DIVIDE_BY_ZERO:1. Alternatively, the measurement could be patched out from the game executable. Let me know if you need more help with either method. For the first one, you'll find some helpful instructions here: https://github.com/narzoul/DDrawCompat/issues/313#issuecomment-2106313374 Some obvious differences: the program name should be "Carnivores" (or whatever you like), the executable should be HuntD3D.exe, and when selecting the IgnoreException shim, you should also click the Parameters button to enter the command line I mentioned earlier: INT_DIVIDE_BY_ZERO:1.

raptor264 commented 4 weeks ago

I did it. That solved the graphical problem in Carnivores 1 (it doesn't works in Carnivores 2 and Ice age). thanks a lot! However now the problem is in the sound. does not start. It remains bugged in the sound of the menu and I am using Windows 95 compatibility and before it did not give me that problem in the sound in Carnivores 1.

image

it's ok?

narzoul commented 4 weeks ago

I don't know about the audio issues, it never worked correctly for me, even when using compatibility modes without DDrawCompat. Using Windows 98 compatibility mode, or just enabling the IgnoreScheduler shim in Compatibility Administrator fixes the menu sounds, but as soon as I enter a hunt, the last few milliseconds that were playing in the menu become looped until exiting to the menu again and pressing some button there. I'm afraid I can't really help with audio issues. DDrawCompat doesn't have any audio related fixes either.

It's possible that creating that compatibility setting in Compatibility Administrator somehow overrides Win95 compatibility mode, but it doesn't happen for me. You can try to enable it there too, or just use the IgnoreScheduler shim. If you use Win95 or Win98 compatibility mode, you'll have to set the IgnoreException parameter again, after deselecting it first and then selecting it again (otherwise the Parameters button will be greyed out).

raptor264 commented 4 weeks ago

okay. thanks a lot🙂. You are doing an amazing job.

narzoul commented 3 weeks ago

it doesn't works in Carnivores 2 and Ice age

So what is the issue in those games? Please take a screenshot from each.

raptor264 commented 3 weeks ago

I'll see about that... another very useful thing I need is to know how to use the compatibility manager to make an application detect my operating system as 32-bit to allow me to install a plugin? I'm sorry for talking to you from here for this but I can't find this information on the internet, I don't know any other way to contact you and I think you know a lot about the subject. Then I return to Carnivores.

narzoul commented 3 weeks ago

I don't know, your question doesn't make much sense to me. 32-bit application run fine on any 64-bit version of Windows. Only 16-bit applications don't, maybe you meant that? What plugin for what application? What is the actual error message? Useful reading: https://xyproblem.info/

raptor264 commented 3 weeks ago

It doesn't matter. It was another separate application. Going back to Carnivores 1 first, the 3D was solved but even though it is supposed to have nothing to do with audio, although it fixed the 3D graphics, the sound broke it into an infinite loop that it didn't do before. so it must have to do with ddraw in some way.

narzoul commented 3 weeks ago

Are you saying that with DDrawCompat v0.5.2 you have working audio, and the sound loop only happens with the above patched version of DDrawCompat?