Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not an issue, just a suggestion for the next step #1

Open
adolfintel opened this issue Jul 20, 2020 · 87 comments
Open

Not an issue, just a suggestion for the next step #1

adolfintel opened this issue Jul 20, 2020 · 87 comments

Comments

@adolfintel
Copy link

First of all, congratulations on fixing this problem. I tried fixing this game a few years ago but I was only able to determine that the game was not using 3DNow at all and that the problem was some incorrect calculation. I loved your article, very well written, great fix.

The next logical step now would be... Mass Effect 2: determining what causes the crashes on Illium (when you walk under Liara's office and at the end of Kasumi's loyalty mission). The first one I think is just memory corruption caused by some incorrect handling of pointers, as it can be worked around by switching between fullscreen and borderless; the second one I haven't got a clue, but it might be somethng inside the bink playback code in the game, since it crashes when a bik file is supposed to play.

Again, congratulations on this massive achievement ❤️

@mirh
Copy link

mirh commented Jul 20, 2020

Silent doesn't really care much for the games...
And besides, I believe those crashes are fairly "normal" matter/oversights (like when you turn some texture group size limits too high or low), not the rocket science he usually bang his head against.

@adolfintel
Copy link
Author

@mirh I see your point. Those crashes are almost 100% reproducible on all modern hardware though, especially the one under liara's office which is also mentioned on PCGW.

@mirh
Copy link

mirh commented Jul 20, 2020

I'm sure of it, but I don't really think that's a bug to be fixed in the executable.
It's probably something in the 3D models or game scripts, that should be handles in ME2Recalibrated.. or whatever other mod actually fixing the game.

@riverar
Copy link
Contributor

riverar commented Jul 20, 2020

Can you provide saves that repro this quickly?

@adolfintel
Copy link
Author

Here's a save on Illium under Liara's office: Cleaner_13_Vanguard_271216.zip
Go through the door in front of you, if you're in fullscreen, the game crashes before you can make it to the end of the corridor. This bug was introduced when The Lair of the Shadow Broker was released in 2010.

Here's another save at the end of Kasumi's loyalty mission:
Jane_32_Soldato_221110.zip
This is a very old save but it can be used to trigger the bug, at least on my machine. You'll have to defeat the boss and reach the shuttle, when you do, the game crashes on some machines. I wasn't able to figure out exactly why, and it doesn't happen on specific hardware, some machines are just "cursed" and do it. If you launch the game with -nomoviestartup it won't crash so it must have something to do with bink. The crash is caused by a null pointer inside MassEffect2.exe. It might be trying to play a nonexistent file.

To use the saves, extract the 2 folders into My Documents\BioWare\Mass Effect 2\Save
Copy the entire folder, not just the .pcsav file inside it.

@mirh
Copy link

mirh commented Jul 20, 2020

It might be trying to play a nonexistent file.

If that's the case, then it should be pretty easy to spot files not found with procmon.
Do you have a modded game (like for example with shorter videos?)?. I remember older versions of such mods were bugged with DLCs.

@adolfintel
Copy link
Author

I'm not using mods at all, just the game, fully patched and with all the DLC installed. You can replicate the problem on the origin version.
When I tried to investigate this issue 4 years ago, I used a tool similar to strace to intercept system calls (I don't remember the exact name of the tool) and there were a lot of file not found errors, even during normal gameplay: missing packages, missing cutscenes, missing loading screens. I imagine they're leftovers from early versions of the game because the game plays normally.

@Mgamerz
Copy link

Mgamerz commented Jul 21, 2020

From what I can tell this only happens to users in full screen mode.

The engine will look in multiple locations to find files, it not finding them at the first location is normal.

@riverar
Copy link
Contributor

riverar commented Jul 21, 2020

@adolfintel Do you have a workaround for the "Unable to authorize the listed DLC"? I used an option in Mass Effect 1 to bypass this, does one exist for Mass Effect 2?

@adolfintel
Copy link
Author

@adolfintel Do you have a workaround for the "Unable to authorize the listed DLC"? I used an option in Mass Effect 1 to bypass this, does one exist for Mass Effect 2?

I have it but I don't know if it's a good idea to post it here since it's technically a crack. Do you need it?

@riverar
Copy link
Contributor

riverar commented Jul 21, 2020

@adolfintel No worries, got the DLC unlocker!

@riverar
Copy link
Contributor

riverar commented Jul 21, 2020

@adolfintel Can't reproduce the crashes sadly. :(

@adolfintel
Copy link
Author

That's good to know. What resolution are you playing at? Did you try fullscreen and borderless modes?
The issue has been known for years and I've always been able to replicate it: https://www.pcgamingwiki.com/wiki/Mass_Effect_2#Game_freeze_on_Illium

@riverar
Copy link
Contributor

riverar commented Nov 8, 2020

Still can't reproduce this, any other ideas? Tried windowed, fullscreen windowed, fullscreen, various resolutions. I'm using the latest Steam version of the executable, with ME2 DLC Unlocker.exe applied to make life easier. (This makes the file version 1.2.1604.0.)

SHA-256 of MassEffect2.exe: C78DB175B4296E403561AEC336BAA02E32E3677C3A374A795FD39C0FD4A85090

Example of one tested configuration
image

@riverar
Copy link
Contributor

riverar commented Nov 8, 2020

Some questions:

  • Do you have any gamepad or other input devices plugged in? Joysticks? Controllers?
  • Any mods installed? Trainers in use? NOCDs?
  • What's the full name of the default/primary audio device? (i.e. where do you hear game audio from?)
  • What version of binkw32.dll do you have in the Binaries folder?

@adolfintel
Copy link
Author

Some questions:

* Do you have any gamepad or other input devices plugged in? Joysticks? Controllers?

Nope, just mouse and keyboard

* Any mods installed? Trainers in use? NOCDs?

No mods, I'm using a cracked exe with the binkw32.dll that unlock all the DLC. I was also able to replicate the issue with the origin version so the crack is not to blame.

* What's the full name of the default/primary audio device? (i.e. where do you hear game audio from?)

Nothing special, Realtek HD Audio. The device is set to its default 44100Hz 16bit stereo configuration. NVIDIA HDMI Audio is also installed but not in use.

* What version of `binkw32.dll` do you have in the Binaries folder?

https://github.com/Erik-JS/masseffect-binkw32

I know the kasumi crash is kinda rare but the crash on Illium can be replicated on all of my machines.

@adolfintel
Copy link
Author

@riverar By the way, I have some experience with tools like IDA pro. I wasn't able to find out anything useful by myself but you clearly know more about it than I do, so if you give me a few pointers I might be able to investigate it further

@riverar
Copy link
Contributor

riverar commented Nov 8, 2020

I have no insight to share on this issue, ha! At this point, I'm just trying to reproduce the issue so we have somewhere to start.

Can you perform the following steps and reproduce the crash? We'll at least have a stack to look at.

  1. Open Regedit, navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps (create the LocalDumps key if needed).
  2. Create a REG_DWORD value named DumpType and set its data to 2.
  3. Reproduce the crash.
  4. Find the MassEffect2.exe.dmp in %LOCALAPPDATA%\CrashDumps, zip it up and upload it to OneDrive/send me a copy ([email protected]). (It may contain PII, so do not recommend attaching it here.)
  5. Repeat step 1 above then delete DumpType to clean up.

@adolfintel
Copy link
Author

Ok, I'll get back to you in a day or two with all the info I can find.

By the way, can you make a pastebin with the hashes of all the files in your ME2 installation? Especially those regarding the Kasumi DLC

@riverar
Copy link
Contributor

riverar commented Nov 10, 2020

@adolfintel Per request report.zip

@adolfintel
Copy link
Author

@riverar Thank you. Did you get my email with the dumps?

@riverar
Copy link
Contributor

riverar commented Nov 10, 2020

@adolfintel oops just dug it out of my junk folder, let's take a peek!

@riverar
Copy link
Contributor

riverar commented Nov 10, 2020

@adolfintel Thanks, sent you a few emails back. Just a heads up, in case those end in the junk mail folder.

@adolfintel
Copy link
Author

I got them, running the tests now. I can tell you right away that RTSS was not the problem and OBS was not running

@adolfintel
Copy link
Author

@riverar Check your email :)

@adolfintel
Copy link
Author

@riverar I sent you another email with a full dump of a kasumi crash, hope that helps

@adolfintel
Copy link
Author

adolfintel commented Nov 15, 2020

So, I'm 90% sure that the kasumi crash is caused by some Windows update that came out between 2014 and 2016.

I have some old hardware and software here so I decided to try various combinations:

  • Windows 10 LTSC 1809 + Modern hardware (6700k+GTX1080): crash occurs
  • Windows 10 LTSC 1809 + Old hardware (Q6600+HD6970): crash occurs
  • Windows 7, fully updated + Modern hardware: crash occurs
  • Windows 7, fully updated + Old hardware: crash occurs
  • Windows 7, SP1 only (2011) + Modern hardware: no crash but driver issues, not recommended
  • Windows 7, SP1 only (2011) + Old hardware: no crash
  • Windows 8.1 Update 1 (2014), no updates + Modern hardware: no crash

Personally, I recall playing the game without issues in 2014, but having the crash in 2016, and this matches what I'm seeing here.

Thoughts?

@adolfintel
Copy link
Author

@riverar
Don't get your hopes up, but I think I fixed the kasumi crash!

I'm sending you an email with a modified exe and more info, but here's what I found out:
The kasumi crash is caused by a null pointer being dereferenced. There is a piece of code that does something like this:

struct stuff=myFunction();
if(stuff.a==NULL) return; else{code...}
if(stuff.b==NULL) return; else{more code...}
...

The thing is: it never checks if stuff is NULL in the first place. So, I modified it so that after getting the value of stuff, it would jump to a small piece of code that I put in one of the empty areas in the exe where it checks if it's NULL, and if it is it returns from the function, otherwise it runs the original code

The crash seems to have been fixed, and while I haven't played through the entire game yet, it doesn't seem to cause problems so far.

Now obviously I can't post a cracked exe on github, even if it's just a fix, so with your help, I'd like to make something like SilentPatch that injects the modified code. Can you do that?

@mirh
Copy link

mirh commented Nov 15, 2020

There are really countless of reports before 2014, so I'm afraid it's not Windows (also, I don't think 2011 drivers should have problems with a 2010 game?).

Also.. Maybe the issue isn't that the NULL pointer has no checks, but rather that sometimes it ends up being NULL?
Anyway, I don't think silent's interested in any further ME'ing, especially if we are talking about something this "mundane".

But I'm sure @Mgamerz will have some ideas (hex editing seems a no-go on origin stupidly obfuscated exe, but maybe the binkw32 loader could come to the rescue)

@adolfintel
Copy link
Author

@mirh True, reports of it exist as back as 2010, but as I remember, it was a rare issue, now all of my machines are affected, which is what made me think of a windows update.

Anyway, I'm starting a playthrough with my modified exe to see if it's stable or not. Would you like to try it?

@JohnA2
Copy link

JohnA2 commented Feb 18, 2023

It's not much.. but it's at least suspicious that the first time I have ever noticed such difference is in the game that seems also to sensitive to that not to crash.

For me it crashed in both fullscreen and borderless windowed mode. Windowed mode just reduced the probability of crashing in a particular place, for example on Illium. My impression is most crashes in this game is related to race conditions between threads. That's also why it crashes more on a modern hardware. Some threads run faster than they used to, which exposes bugs that were always there, but were hidden during the game testing because they almost never caused crashes in practice before.

A good example of it is the crash after the Kasumi's loyalty mission that @adolfintel fixed. Before I found his fix, I tried to finish the mission several times and it crashed on every single attempt. At first I thought it might be due to a missing file and tried to check it with Process Monitor. And guess what, the game didn't crash with Process Monitor running in the background! Of course Process Monitor didn't magically fix the game, all it did was slowing down the right thread that was running too fast before, so this time another thread had enough time to populate the data that the first thread required, and the pointer mentioned in https://fdossena.com/?p=kasumifix/i.md wasn't null anymore. At least that's the only logical explanation I can think of.

@mirh
Copy link

mirh commented Feb 22, 2023

That's sensible..
I wonder if setting single thread affinity, or playing with thread priorities (can easily be done with process hacker) could help.
Also I found this pretty intriguing report.

And FWIW I just finished some kind of theory for my aforementioned discovery after like half a day of tests and loosing my faith in god (at one point I even came to think autologin could control the unexplained behaviour I still can not get at the bottom of, but then it suddenly didn't seem to make a difference anymore)

@adolfintel
Copy link
Author

@mirh I remember trying to set single thread affinity when I first encountered these issues and it didn't do anything other than make the game more stuttery. That wine report is probably just a wined3d bug from back then, I had no issues with it on wine-ge with dxvk (tested a few weeks ago).

I think our best bet if we want to fix the Illium crash is some variant of what @JohnA2 suggested with the modified video file. Ideally, we would want some way to either modify the Illium map so that it loads an empty video file or replace the original file with an empty one and modify the Liara apartment map so that it points to a copy of the original video with a different name.
I have no idea how to do this of course or I would have done it myself. Do you know how to use ME Explorer and similar tools to do something like this on cooked files?

@mirh
Copy link

mirh commented Feb 22, 2023

Not really, even though I'm sure everything and anything can be done with them by now.
Can't be much harder than clicking "find references" to the object and then replacing texture names?

@JohnA2
Copy link

JohnA2 commented Feb 22, 2023

I think our best bet if we want to fix the Illium crash is some variant of what @JohnA2 suggested with the modified video file. Ideally, we would want some way to either modify the Illium map so that it loads an empty video file or replace the original file with an empty one and modify the Liara apartment map so that it points to a copy of the original video with a different name. I have no idea how to do this of course or I would have done it myself. Do you know how to use ME Explorer and similar tools to do something like this on cooked files?

The video plays in the Liara's office, not apartment. As I mentioned above, replacing the video with either an empty one or a different one from the game with ME Explorer works but doesn't fix the crash, so I had to disable it with hex editing instead. I think not having that 8 seconds video is a small price to pay to avoid the crash that happens so often. The video only plays once when you start the Shadow Broker mission, so people who want to see it can temporary replace BioD_TwrHub_504LiaraDLC_LOC_int.pcc modified per my instructions with the original file just before starting the mission, start it, and then replace it with the modified .pcc again. Not ideal, but I don't see another way without patching the .exe. Probably a fix like you did for the Kasumi crash would work, but if you already looked into it and couldn't do it in this case, we're most likely out of luck with a more proper fix that would keep the video.

That's sensible.. I wonder if setting single thread affinity, or playing with thread priorities (can easily be done with process hacker) could help.

It may reduce the chances of a crash if you're very lucky, but it can't fix it completely. The only good fix would be implementing the proper thread synchronization by changing the game code. But it can be difficult even when having the source code. Fixing thread synchronization with reverse engineering seems next to impossible to me, but I'm not an expert.

Also I found this pretty intriguing report.

They mention the Illium car chase issue. I remember reading that some people also had a crash during that scene, but it never crashed there in my case. I only noticed a slight corruption of the video for a second there. Maybe that can cause an issue. If that's true, re-encoding that video might fix it. But I can't try it as it never crashes for me.

And FWIW I just finished some kind of theory for my aforementioned discovery after like half a day of tests and loosing my faith in god (at one point I even came to think autologin could control the unexplained behaviour I still can not get at the bottom of, but then it suddenly didn't seem to make a difference anymore)

I think not many people play in windowed mode, so it was likely tested the least. I finished the game in fullscreen mode. After applying the @adolfintel's fix and my fix, I didn't have any major issues anymore. It still crashed a few times at random places, but I was always able to continue without the same crash happening at the same place again. The only other persistent crash I encountered was at the beginning of Prometheus Station (Overlord DLC). The fix in that case was not bringing Legion as a squad member, see https://fextralife.com/forums/t216365/overlord-crash-at-prometheus-station . Overall it seems that most issues are with DLCs that were released after the last patch. Probably Bioware stopped working on fixing bugs at that point.

@adolfintel
Copy link
Author

Yeah, I know about that car chase crash (the whole LTSB mission has several spots where it occasionally crashes: this one, the scene with Vasir in Liara's apartment, the scene with Liara after killing Vasir, on the shadow broker's ship near those stabilizer things that move up and down and spark, when the door opens after the fight while waiting for Liara's hacking thing to finish, and probably more that I'm forgetting.
I'm not sure what causes them and I never investigated the issue because you can just restart the game after the crash and it won't crash again at that spot. Illium and Kasumi on the other hand really piss me off. I'm glad that I was able to fix Kasumi since it was game breaking but I wasn't able to figure out how to prevent the freeze on Illium.

@JohnA2 did you try reencoding the video inside BioD_TwrHub_504LiaraDLC_LOC_int.pcc?

@JohnA2
Copy link

JohnA2 commented Feb 22, 2023

@adolfintel No, I didn't try reencoding that video. I believe that if replacing it with other videos didn't fix the crash, the problem is in how the game processes the video (during texture caching I guess) in that particular spot, not the video itself. I checked other .pcc files for similar cases and found that a video embedded in a texture like that is a pretty rare case in the game, that's probably why that bug doesn't cause crashes in other places. The car chase crash sounds like a different issue, that's why I thought reencoding might help there.

@adolfintel
Copy link
Author

adolfintel commented Feb 23, 2023

Quick update on the Illium freeze.

I spent a few hours investigating the issue. I'm not 100% confident about the stuff that I'm about to write, my reverse engineering skills are very limited, but here goes.

I think the freeze is caused by the rendering thread (conveniently named RenderingThread, thanks game): at address 0x51147f it tries to do a mov eax,[ecx], where [ecx] seems to be a function pointer loaded from memory. When the freeze occurs, the pointer contains garbage data and the rendering thread crashes.
Interestingly, the other threads keep going and we see a freeze because the main thread is waiting for the rendering thread.
If this is correct, the freeze might be caused by a race condition between the thread that populates the memory area read by the rendering thread. This would also explain why on linux the crash occurs about 25% of the time, regardless of fullscreen/borderless, and why @JohnA2's workaround works. A simple sleep in the right place might be enough to fix this problem, but where...

Edit: placing a breakpoint at 0x511470 (before the pointer is read from memory) seems to fix the freeze by introducing some delay, I just need some way to automatically resume execution after a few ms instead of having to press the resume button in IDA.

@adolfintel
Copy link
Author

Oh my god, I think I fixed it 😱

I modified the exe to add a short sleep at the beginning of that function, that seems to be enough, instead of crashing it does a small stutter. I haven't tested it extensively yet, but I went back and forth over 20 times without crashing. I'll keep you posted 🤞

@JohnA2
Copy link

JohnA2 commented Feb 24, 2023

@adolfintel That sounds promising. A sleep is still not a proper way to do thread synchronization, but it's probably the best chance to fix it when the source code is not available. If you can tell the offset in the .exe to modify, I can test it as well.

Also maybe worth noting that this Illium issue was a bit different for me on Windows 11 and 7. On 11 it's a freeze with no error, but on 7 it's a crash with the usual Windows error message. So maybe if you still have access to win7, it would be easier to debug there. When it crashed, the exception offset was either 00111481 or 0011147f.

@adolfintel
Copy link
Author

@JohnA2 It's definitely not ideal (and I don't like seeing a hiccup every time I go through that tunnel), but it's better than nothing.

As I said, it's not extensively tested yet (just got back from work) and it may not work at all, but here's what I changed in my exe:

00111463 CC 60
00111464 CC 6A
00111465 CC 64
00111466 CC FF
00111467 CC 15
00111468 CC DC
00111469 CC F1
0011146A CC EE
0011146B CC 00
0011146C CC 61
0011146D CC EB
0011146E CC 3A
00111471 56 EB
00111472 8B F0
00111473 71 90
00111474 04 90
001114A9 CC 56
001114AA CC 8B
001114AB CC 71
001114AC CC 04
001114AD CC EB
001114AE CC C6

For reference, my exe has a SHA1 of 7abb09fa20a4476a7b6f84d1824836db37a2efda so don't try this if your exe is different.

I'll test this a bit and then make an ASI to share it if it works.

@JohnA2
Copy link

JohnA2 commented Feb 24, 2023

@adolfintel My .exe is a bit different. The SHA1 doesn't match and also the "56 8B 71 04" sequence starts at 00111470 instead of 00111471. Not sure if it's just a mistake you made because the shift is only 1 byte.

Anyway, I think the main question is how many times the game hits the code where you added sleep. If it's rare, occasional hiccup is fine. If not, personally, I would still rather sacrifice the 8 seconds video instead. It's not an important video for the story, it's just a little weird when Liara looks at an empty datapad screen for a few seconds and says "It looks like a leaked transmission between Shadow Broker operatives" before the picture of Feron finally appears 😄

@adolfintel
Copy link
Author

adolfintel commented Feb 24, 2023

@JohnA2 I'm attaching the ASI so you can test it (source included of course), hopefully it works with different exes too, the one I have is a cracked one from reloaded I think.
I have a ton of saves and I'm going through every area to see if it causes lag spikes or freezes, the only area I found so far is the shadow broker ship, in that room where you can watch a bunch of surveillance videos, there's a ~1 second freeze when unloading the area but it's not a problem because it happens during a loading screen. There may be another spike like this on Freedom's Progress when the scared quarian guy shows you the surveillance video but I haven't played that mission yet. I'm not aware of any other "bink textures" in ME2 afaik, other videos like the ads on the citadel are not prerendered.

ME2IlliumFreezeFix.zip

@JohnA2
Copy link

JohnA2 commented Feb 24, 2023

@adolfintel Thanks! I've tried it and it says the patch was successful. I also noticed the hiccup that you mentioned, but unfortunately on the fifth attempt to pass the tunnel it still crashed for me. The exception offset was 00111481 as before. But the frequency of this crash definitely reduced with your patch.

the only area I found so far is the shadow broker ship, in that room where you can watch a bunch of surveillance videos, there's a ~1 second freeze when unloading the area but it's not a problem because it happens during a loading screen. There may be another spike like this on Freedom's Progress when the scared quarian guy shows you the surveillance video but I haven't played that mission yet.

These are exactly the places where I found that other "TextureMovie", as ME Explorer calls it, are used, so modifying that code shouldn't affect much of the game, which is really great if a more reliable fix can somehow be made.

@adolfintel
Copy link
Author

Hmm, that sucks. I didn't get a single crash in about 50 tries, I even went into Liara's office and it played the video just fine, I guess the different thread scheduling in linux is involved. 1 chance of crashing out of 5 is a good start though, it used to be ~100% for me on windows before this.

Offset 111481 corresponds to 0x511481 in memory, which was one of the crash spots without the sleep.
I wonder why it doesn't crash on the shadow broker ship where there are a ton of those videos though...

If the sleep is not enough to reliably fix this maybe we can figure out a better solution. You seem to know ME Explorer better than me, do you think there's some kind of "loading volume" near liara's office? If so, would it be possible to remove it or move it out of the way?

@JohnA2
Copy link

JohnA2 commented Feb 24, 2023

I even went into Liara's office and it played the video just fine

That part also never crashed for me. Only going through the tunnel under the Liara's office or (more rarely) near the tunnel entrance did.

I guess the different thread scheduling in linux is involved.

Yes, this is definitely a factor when a race condition is involved. In my case the crash frequency with the unpatched game was also different depending on the OS and hardware, even though I only tried it on Windows.

1 chance of crashing out of 5 is a good start though, it used to be ~100% for me on windows before this.

With my fix it never crashed on my 2 systems anymore. Not sure if it's just luck with the race condition or if the code that causes the crash is simply not executed after I "disable" the video.

You seem to know ME Explorer better than me, do you think there's some kind of "loading volume" near liara's office? If so, would it be possible to remove it or move it out of the way?

I'm also not that good with ME Explorer. I just tried it and was able to figure out how to do things because its UI was intuitive enough for me. I tried to adjust all variables that were associated with the texture/video, but it made no difference.

Honestly, I'm satisfied with my "disabling video" fix enough to stop looking for other options. Fixing thread synchronization would've been a perfect fix because it might fix other random crashes as well, but doing it in assembly is above my skills. Another alternative I thought of was replacing the video on the datapad with a series of quickly changing images because images don't seem to cause crashes. But that would require some ME modding skills.

@adolfintel
Copy link
Author

The reason I don't like the "disabling video" fix is not just because you lose that 8 second video, it's because the problem is still there and waiting to be triggered again by unknown conditions. I don't like the sleep workaround much better.
I'm trying to figure out how to use the package editor in ME explorer to see if I can find any differences between the Feron video and the other TextureMovies.

@adolfintel
Copy link
Author

adolfintel commented Feb 24, 2023

Only difference I see is that there are several copies of this stupid video in the localization files, while the other TextureMovies only appear once. Replacing the video file with another TextureMovie seems to always cause a crash when approaching the door

@JohnA2
Copy link

JohnA2 commented Feb 24, 2023

the problem is still there and waiting to be triggered again by unknown conditions

I completely agree here, but I think it would take a reverse engineering expert to come up with a proper fix in this case.

I'm trying to figure out how to use the package editor in ME explorer to see if I can find any differences between the Feron video and the other TextureMovies.

I think there's no difference in the embedded bik files. One of the replacement videos that I tried was from another TextureMovie from Freedom's Progress and that video still caused a crash on Illium, even though it doesn't seem to crash on Freedom's Progress.

It feels like that Illium location is a somehow unique combination of TextureMovie and other things. Like I mentioned, disabling dynamic shadows was another thing that seemingly 100% fixed the crash for me (I just didn't like that solution). I also noticed that while the crash inside the tunnel can happen at any time, a more rare crash just outside the tunnel only happened closer to sunrise or sunset and not during the day. These 2 observations with shadows and the sun position might be just a coincidence and not mean much, but if they do make a difference, it would explain why it doesn't crash on Freedom's Progress and the Shadow Broker base with TextureMovies present there as well.

@mirh
Copy link

mirh commented Feb 25, 2023

Indeed, given that BioD_ProFre_501Veetor.pcc has actually another duplicated ProFre_501_VeetorFootage if you search for (TextureMovie) through the dumps of package dumper (even though only in the italian localization).

Btw FWIW I see the BioMoviePlayer class in SFXGame has a lot of null checks. Maybe you could try playing with them?

p.s. wine tries to stick with windows threading model as much as it can IIRC, what happens here could even be (somewhat paradoxically) that they don't have the same compatibility regards that windows would have.

@adolfintel
Copy link
Author

adolfintel commented Feb 25, 2023

Another quick update on the Illium freeze.

I added a little "safety net" before the function pointer read from memory is used at 0x511481, a simple loop that freezes the rendering thread until that pointer in memory points inside the code segment. This brought down the crashes to 0% (on linux) when running in borderless mode, but fullscreen still freezes indefinitely when the usual freeze occurs (pointer gets corrupted maybe?).

I'll keep you posted.

@adolfintel
Copy link
Author

Alright, time for another update on the Illium freeze.

Here's what I got at the moment:

  • I have a stinking suspicion that the function at 0x511470 shouldn't even be called at all. This function only gets called when the game freezes/crashes, it doesn't get called when we occasionally go through the area without a freeze/crash
  • When dynamic shadows are disabled, the function doesn't get called at all and the game never freezes/crashes
  • With my sleep and safeguard workaround we can go through that function and I can see that the function pointer that gets read too early points to a function at 0x41b0e0, the function has to do with dynamic shadows, not bink!
  • With my sleep and safeguard workaround, the game continues without crashes (tested a lot at this point) but I noticed that the Salarian in the next room (the guy looking for his "pedigree") has its idle animation corrupted, that hints to possible memory corruption while loading the area. Nothing else seems to be affected
  • I cannot for the life of me replicate @JohnA2's 0 size bink file workaround, if I so much as hit save on that pcc file without changing anything, the game loads infinitely or freezes when I go anywhere near the tunnel. What version of ME Explorer are you using?

@JohnA2
Copy link

JohnA2 commented Feb 26, 2023

@adolfintel Your findings are very interesting. I suspected that this bug is caused by a combination of dynamic shadows and TextureMovie because eliminating one of these two things seems to fix it. I used ME3Explorer 5.1.0.2851 from https://github.com/ME3Tweaks/LegendaryExplorer/releases . I also experienced what you described with older ME3Explorer versions. There are newer versions called Legendary Explorer as well, but I haven't tried those.

@CookiePLMonster
Copy link
Owner

Another quick update on the Illium freeze.

I added a little "safety net" before the function pointer read from memory is used at 0x511481, a simple loop that freezes the rendering thread until that pointer in memory points inside the code segment. This brought down the crashes to 0% (on linux) when running in borderless mode, but fullscreen still freezes indefinitely when the usual freeze occurs (pointer gets corrupted maybe?).

I'll keep you posted.

With this you may potentially be able to find the function producing that pointer - if it's done from only one or two places, it may be enough to jerry rig proper event-based synchronization there.

The downside is obviously that it's hard to prove you cover all the code so if something remains unpatched it might introduce deadlocks, which isn't optimal either.

@adolfintel
Copy link
Author

@CookiePLMonster I have no idea how to do it. I tried placing a breakpoint on writes but it's in a different place every time.
You're way more experienced than I am, what would you suggest?

@CookiePLMonster
Copy link
Owner

That may be tricky then, maybe time travel debugging in WinDbg could help but I never used it. Perhaps if you go up the call stack, you are eventually going to hit some object that is on a static address or at least easier to debug?

@adolfintel
Copy link
Author

The thing is, I don't even know which thread is writing that data, I looked at the stacks for the main thread, the rendering thread and the IO thread and I couldn't figure out what was going on, they're long and by the time the game crashes the function that messed up the pointer may have already finished running and its data overwritten by other calls. There are also other threads for audio and who knows what else, but their stack is very small and I doubt they're involved.

I'll try that time travel feature tomorrow (gotta work today) and let you know if I discover something.

(I have to say, this and the kasumi fix combined would be prime SilentPatch material 😉 )

@adolfintel
Copy link
Author

Been a while, huh?

After giving up in february, today I tested the game again, and it seems that this option in Valve's version of Wine fixes the freezing on Illium: export WINE_HEAP_DELAY_FREE=1. It's a workaround that was introduced for games that have use-after-free bugs, it shouldn't break anything.

So if you're using Proton, Wine-GE (or my TDF project) you might want to give it a try.

@mirh
Copy link

mirh commented Aug 8, 2023

You mean, that it fixes the crashing problem even without your patch?
If yes, then I wonder if the EmulateHeap, FaultTolerantHeap or any of the 8 Heap* ACT shims in W10 couldn't also help?

@adolfintel
Copy link
Author

My patch was just a shitty workaround that didn't work 100% of the time, that's why I never released it. This seems to have solved it... for now at least.
I don't have Windows installed at the moment to test those settings but if you do then give it a try, maybe we can add it to PCGW as a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants