-
Notifications
You must be signed in to change notification settings - Fork 42
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
OpenTESArena crashes when using a release build of WildMIDI #192
Comments
Might (or might not) be a double free()?? Can you give us the midi file, so that we can test and reproduce without |
Thanks for writing this up, @Allofich. Just to add some more information, I think this is just an issue with the Windows build of WildMIDI, and assuming that WildMIDI is calling This crash also happens when a song finishes in the console, but only when I use WildMIDI's build. When I compile WildMIDI myself with RelWithDebInfo and Visual Studio 2015, the console doesn't crash when a song finishes. Edit: @sezero, the MIDI files are available in issue #149. It's not just .XMI and .XFM files that cause WildMIDI to crash on free, though (also .MID files converted by WildMIDI). |
MSVCP80.DLL and MSVCP140.DLL are not supposed to mix: issue I can't crash it on linux by running under valgrind. Can you make it crash if you build current git master branch with |
You mean make a release build of current git master branch of WildMIDI? Yes, it crashes for me, using the built .dll with OpenTESArena. Also the MIDI I was having a problem with was PERCNTRO.XMI, different from the ones afritz1 linked to, but I tried those (OVERSNOW.XMI, SUNNYDAY.XMI, VISION.XMI) and they have the same problem. In all cases the crash happens at Line 1938 in b008d78
OpenTESArena calls |
I put a debug print in there, like:
With either of OVERSNOW.XMI, SUNNYDAY.XMI and VISION.XMI, I don't ever |
@psi29a: can you reproduce this in a simple way? |
@Allofich: can you crash your built dll if you play those XMI files |
@sezero I'll see if I can repro this on Linux (release/debug builds). I don't have a windows box to test sadly. |
My tests were on linux, btw: I failed to reproduce using wildmidi-only. BTW, I pushed db42139: there was a duplicated check in there. |
I am not good with C++ so this may sound stupid, but, does setting
|
I tried it now. I have never used the wildmidi.exe player before so I'm not sure about how to set up .pat sounds for it. However even without those it can silently "play" OVERSNOW.XMI, which I am using as a test. ~~~There is no crash on exit. However for me it does use the line I mentioned above, many times in fact. I have fprintf commands around that line and on closing OVERSNOW.XMI they are printed 21 times.~~~ By the way using the wildmidi.exe from the releases page it complains that the .XMI file is not a MIDI file, but with the one I built from source it can play silently as I described above.
I'll try this next. |
So anyway, since I have a crash on the same line with a release build of wildmidi.exe when closing OVERSNOW.XMI in Windows7 64-bit, and it seems sezero on Linux does not, it seems to confirm that:
|
Did a test. I added fprintf statements for the number of events and the event types in that section of crashing code, like
Result for OVERSNOW.XMI was Looks like it crashes on the first event in each case, which is always |
@Allofich: does the mingw build from wildmidi-0.4.2-win64 (or -win32) release If it works properly, it has something to do with MSVC?? And it sohould not be |
The mingw build is the one in the main folder (not the msvc folder) when I extract wildmidi-0.3.13-win64.zip, right? But as I said above, I cannot play the MIDI, because it says
Visual Studio 2015. Specifically: |
0.3.x series don't have xmi support. Try with wildmidi-0.4.2-win64.zip instead. |
Oh, I downloaded just the first one I saw at the top of the page because I thought it was newest. 0.4.2 works, and there is no crash with the mingw build! It does crash with the msvc build in that package. |
So it is msvc related? |
So, MSVC is allergic to and/or miscompiling something. Affected MSVC versions I can't see anything wrong by just following the code, so I don't know what it |
Seems so. Also, back to afritz1's comment:
sezero responded:
but I think afritz1 was also saying they are not supposed to mix. He suggested in the original thread over at OpenTESArena's issue tracker:
|
To be honest I don't quite understand what he was saying, though. If he means that mismatch is between the .dll used in OpenTESArena and WildMIDI then that is probably not the issue, since WildMIDI crashes on its own. |
That your own wildmidi_dynamic.dll build using VS2015 is crashing |
Ok, thanks. I thought that should be the case. |
Besides, I can happily lose the MSVC builds in future builds: |
In any case, I will test myself on windows soon, using MSVC (I have 2005 and 2017). |
Oh, well, I will leave that to @afritz1 to comment about, since OpenTESArena is his project. |
Ok. I think it would be best if the problem could be fixed for MSVC, but I will leave it to you. |
I built the current master branch for win64 using vs2017 (release build.) When it reaches completion, it pauses noticeably, and just 'exits', The mingw-w64-built 0.4.2 version behaves properly. |
valgrind it! Can we use wine and valgrind to get to the bottom of this? (gdb?) |
I wish :) No valgrind for windows, and I don't know whether
Don't know, never ever tried such a thing, be my guest :) |
Just to let you know, Visual Studio's "Code Analysis" (built-in static analysis) includes a number of warnings about possible dereferencing of null pointers, etc., including in code in the neighborhood of the problem area. I don't know the severity of these warnings, whether they are false positives or the like, but I've tried running Code Analysis on a few different projects and I don't recall ever seeing this many warnings about potential memory problems, so it may at least be worth looking at. For reference, here is the output (using latest master branch):
There are other warnings as well, but these are the most interesting ones. I haven't examined these, but who knows, maybe addressing something in here will solve something that is tripping up MSVC, or maybe there is something worth fixing for all platforms. |
I tried the MinGW build of WildMIDI 0.4.2 and songs finish as expected, so that's more evidence that it's a problem between WildMIDI and MSVC (or more WildMIDI because MSVC runtime conflicts were ruled out).
I guess I was a little unclear there. My point was that having WildMIDI built with a newer MSVC version might fix the problem, but it seems that's not the case, so no worries. WildMIDI does crash on its own, so it can't be a .dll mismatch. @sezero, it's fine if you don't have MSVC builds anymore since WildMIDI is pretty easy to download and build, but it would be better if we can help you get to the bottom of this issue. Maybe that pause you're seeing is Windows silently writing a memory dump somewhere? Just a guess. |
Built for win32 (x86) using Open Watcom 1.9, and the result behaves OK too. Hrmph.. |
Indeed, I'd like that very much (I'm a hopeless perfectionist, so I
Possibly, I don't know. |
I just used wildmidi-0.4.2-win64/msvc/wildmidi.exe under wine and I'm not able to reproduce the problem. |
I'm using L"Microsoft.VC80.CRT" (8.0.50727.6195) |
I did more investigation and found something interesting. The .XMI files were crashing on:
However, I checked the .XMI file for what events were being created while processing it, and I then thought to check whether Both of these functions are only "placeholders" as they are commented. They have the same parameters and the same bodies of Changing the So it seems the Release build treats all of these empty functions as equal, leading to the crash. I haven't looked into it but I assume that, for example, |
Nice find! So this is an over-optimization by the msvc compiler? |
Yeah, I told you so: #192 (comment) Maybe this has something to do with linkage??? |
Huh, not impossible |
Why don't we add an event_type member to the struct and compare that |
invent a new enum _event_type, add a new enum _event_type evtype member to struct _event. do all the event type comparisons using the new evtype member instead of do_event function pointer.
Can you guys review and test the new 'bug192' branch? |
@sezero that's a lot cleaner... |
Just tested on Windows using VS2017, the new 'bug192' branch runs OK for me. |
I downloaded the |
Note: Bug #192 happened because Visual Studio, as observed with version 2005 to 2017, optimized several identical empty functions into one, but the code used function pointer comparisons which led to false positives and crashes.
* fix Visual Studio builds (bug #192): invent a new enum _event_type, add a new enum _event_type evtype member to struct _event. do all the event type comparisons using the new evtype member instead of do_event function pointer. * added enum _event_type:ev_null (for bug #192) * fix build (typo.) * updated changelog for 0.4.3. Note: Bug #192 happened because Visual Studio, as observed with version 2005 to 2017, optimized several identical empty functions into one, but the code used function pointer comparisons which led to false positives and crashes.
OK, then. Changes merged to master as of da69848 Closing as fixed. Thanks for the report and identifying the root cause. |
Thanks for reporting and digging into the problem! :) |
The latest master branch works fine for me as well. Thanks for the fix! |
I'm in the process of setting up a windows10 machine for development and testing. Would of been done by now except I had to get the first one replaced after it failed. Will also be V'boxing ubuntu and freebsd. So scrolling up ... and down, as well as checking the commits. Gah I dislike optimisation bugs. While I like how this problem was fixed I gotta ask, if MSVC was combining simular functions, would a simpler work around be done by adding like an char _WM_someuniquename = some unique value; to each of the functions in internal_midi.c? |
I might have been simpler, perhaps, but I felt that the current |
I think the current way is cleaner, it's pretty much why a switch statement exists. :) |
Link to the original issue afritz1/OpenTESArena#69.
OpenTESArena uses WildMidi. If run with a Debug or RelWithDebugInfo build of WildMIDI, no crash happens, but if run with a Release build, a crash always happens. Only tested on Windows 7, 64-bit.
Steps to reproduce crash:
First you need OpenTESArena running with MIDI.
It requires a copy of The Elder Scrolls: Arena (the free, floppy-disk version released by Bethesda Softworks) to be installed. It's easy to find. Next,
https://github.com/afritz1/OpenTESArena/releases/download/opentesarena-0.1.0/eawpats.zip
or
https://github.com/afritz1/OpenTESArena/releases/download/opentesarena-0.1.0/eawpats.tar.gz
and put the extracted contents into the OpenTESArena
data
folder.Make sure you set the path to your installation of Arena in the OpenTESArena options file. The easiest thing to do if you just want to quickly get the game up and running is to directly modify the default in the
options-default.txt
in the OpenTESArenaoptions
folder.Try the game, it will run fine.
Now replace the supplied
wildmidi_dynamic.dll
, which I think is a RelWithDebugInfo build, with a Release build of WildMIDI. (As of this writing the latest commit is b008d78)Start the game. It is fine until you try to leave the title menu to start the game, for example by clicking "Test" at the bottom of the screen, or when you exit the game. For information on the code in OpenTESArena involved in the crash and the specific line in the WildMIDI code that the program crashes on, please see the issue over at OpenTESArena I linked to above. It seems it may have something to do with
_WM_do_meta_copyright
.The text was updated successfully, but these errors were encountered: