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

Breakout crashes on Windows with bgfx video driver #6106

Closed
MooglyGuy opened this issue Dec 27, 2019 · 10 comments
Closed

Breakout crashes on Windows with bgfx video driver #6106

MooglyGuy opened this issue Dec 27, 2019 · 10 comments
Assignees

Comments

@MooglyGuy
Copy link
Contributor

There is the following issue on MAMETesters: https://mametesters.org/view.php?id=7531

However, I cannot debug the issue. VS2019 is my preferred debugger, and in an actual debug-enabled build, there are numerous assorted asserts that get thrown well before the crash can even occur.

@couriersud needs to sort out his own house before I can even begin to properly diagnose what's up with the BGFX rendering backend.

@couriersud
Copy link
Contributor

I have updates to the fixedfreq monitor code pending for weeks now which also should fix some edge cases in addition to a speed improvement. I have a look into the asserts issues and will fix those.

@couriersud couriersud self-assigned this Dec 28, 2019
@couriersud couriersud changed the title Breakout & Netlist system are broken Breakout crashes on Windows with bgfx video driver Dec 28, 2019
@couriersud
Copy link
Contributor

Updated title.

@couriersud
Copy link
Contributor

However, I cannot debug the issue. VS2019 is my preferred debugger, and in an actual debug-enabled build, there are numerous assorted asserts that get thrown well before the crash can even occur.

@MooglyGuy Can you please be more specific which asserts get thrown?

I just did using the official build chain

make DEBUG=1 SUBTARGET=nl
gdb mamenl64d.exe
run breakout -video gdi

and I am experiencing no asserts from start to end.
Consequently there is nothing I can do about fixing asserts until I get more information about the asserts which are in your way to fix a - according to the backtrace on mametesters - core bgfx bug.

I do not have a native windows development environment. BGFX will crash immediately on every game in my virtualbox Win7 machine.

@MooglyGuy
Copy link
Contributor Author

Errors:
   Netlist CPU Device device 'maincpu': netlist FATAL: Alias CR5.A was resolved
to be terminal CR5.A. Terminal CR5.A was not found.
   Netlist CPU Device device 'maincpu': Alias CR5.A was resolved to be terminal
CR5.A. Terminal CR5.A was not found.
Warnings:
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP2
.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP1
.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP1
.REVERSE
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP2
.REVERSE

Driver pongd (file pong.cpp): 2 errors, 4 warnings
Errors:
   Netlist CPU Device device 'maincpu': netlist FATAL: Alias B10_R.1 was resolve
d to be terminal B10_R.1. Terminal B10_R.1 was not found.
   Netlist CPU Device device 'maincpu': Alias B10_R.1 was resolved to be termina
l B10_R.1. Terminal B10_R.1 was not found.
Warnings:
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter B10_P
OT.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter B9A_P
OT.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter A10_P
OT.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter B9B_P
OT.DIALLOG

Driver pongf (file pong.cpp): 2 errors, 2 warnings
Errors:
   Netlist CPU Device device 'maincpu': netlist FATAL: Alias R3V.1 was resolved
to be terminal R3V.1. Terminal R3V.1 was not found.
   Netlist CPU Device device 'maincpu': Alias R3V.1 was resolved to be terminal
R3V.1. Terminal R3V.1 was not found.
Warnings:
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter ic_b9
_POT.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter ic_a9
_POT.DIALLOG

Driver rebound (file pong.cpp): 2 errors, 4 warnings
Errors:
   Netlist CPU Device device 'maincpu': netlist FATAL: Alias POTP1.1 was resolve
d to be terminal POTP1.1. Terminal POTP1.1 was not found.
   Netlist CPU Device device 'maincpu': Alias POTP1.1 was resolved to be termina
l POTP1.1. Terminal POTP1.1 was not found.
Warnings:
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP2
.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP1
.DIALLOG
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP1
.REVERSE
   Netlist CPU Device device 'maincpu': netlist WARNING: Unknown parameter POTP2
.REVERSE

Caught unhandled class netlist::nl_exception exception: Alias CR5.A was resolved
 to be terminal CR5.A. Terminal CR5.A was not found.```

@couriersud
Copy link
Contributor

What you experience is that the driver validation fails. I have no idea how this could happen. I have invested quite some time to try to recreate this but had no success.

  • What command line are you using to compile mame?
  • Which command line are you using to run mame and produce the output above?
  • What happens if you run mame64d -validate breakout ?

Once we have solved the validate issue : When debugging with catch throw in gdb there are exceptions which get thrown during validate. Validate is run by the mame core prior to starting the game. The use of exceptions during validate is mandated by the mame core to ensure device order processing. In gdb you have to press c (continue) a couple of times if you run with catch throw - see below.

In the meantime I managed to get bgfx working in my Win7 VM. I can confirm that my next commit will fix the crash when running with bgfx. I think that the crash is triggered when you run a game with a very very high screen refresh rate - e.g. >1 kHz. That can happen in the current code in fixedfreq.cpp during the first couple milliseconds until vsync detection has stabilizied. Same as on a real monitor.

[MINGW64] C:\msys64\src\mamegit>gdb mamenl64d.exe
GNU gdb (GDB) 8.3.1
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from mamenl64d.exe...
(gdb) catch throw
Catchpoint 1 (throw)
(gdb) run breakout -w -video bgfx -bgfx_backend d3d9
Starting program: C:\msys64\src\mamegit\mamenl64d.exe breakout -w -video bgfx -bgfx_backend d3d9

Catchpoint 1 (exception thrown), 0x000000000284da58 in __cxa_throw ()
(gdb) c
Continuing.
[New Thread 3416.0x1b54]
[New Thread 3416.0x1ab0]
[Thread 3416.0x1ab0 exited with code 1]
[New Thread 3416.0xffc]
[New Thread 3416.0x1994]
[New Thread 3416.0x730]
[New Thread 3416.0x5f0]
[New Thread 3416.0x1610]
[New Thread 3416.0x860]
[New Thread 3416.0x37c]
[New Thread 3416.0x177c]
[New Thread 3416.0xd18]
[New Thread 3416.0x18d8]
[New Thread 3416.0x1b90]
[New Thread 3416.0x16c0]
[New Thread 3416.0x5a0]

Thread 1 hit Catchpoint 1 (exception thrown), 0x000000000284da58 in __cxa_throw ()
(gdb) c
Continuing.

Thread 1 hit Catchpoint 1 (exception thrown), 0x000000000284da58 in __cxa_throw ()
(gdb) c
Continuing.

Thread 1 hit Catchpoint 1 (exception thrown), 0x000000000284da58 in __cxa_throw ()
(gdb) c
Continuing.

Thread 1 hit Catchpoint 1 (exception thrown), 0x000000000284da58 in __cxa_throw ()
(gdb) c
Continuing.

Thread 1 hit Catchpoint 1 (exception thrown), 0x000000000284da58 in __cxa_throw ()
(gdb) c
Continuing.

Thread 1 hit Catchpoint 1 (exception thrown), 0x000000000284da58 in __cxa_throw ()
(gdb) c
Continuing.
[Thread 3416.0x1610 exited with code 0]
[Thread 3416.0x5a0 exited with code 0]
[Thread 3416.0x1b90 exited with code 0]
[Thread 3416.0xd18 exited with code 0]
[New Thread 3416.0x111c]
[New Thread 3416.0x175c]
[Thread 3416.0x16c0 exited with code 0]
[Thread 3416.0x111c exited with code 0]
[Thread 3416.0x175c exited with code 0]
[New Thread 3416.0x1504]
[Thread 3416.0x860 exited with code 0]

@firewave
Copy link
Contributor

firewave commented Jan 5, 2020

The netlist validation failures also happen to me with 2001tgm - using Visual Studio 2019:

Driver 2001tgm (file gamemachine.cpp): 2 errors, 0 warnings
Errors:
   Netlist Sound Device device 'snd_nl': netlist FATAL: Alias R2.2 was resolved to be terminal R2.2. Terminal R2.2 was not found.
   Netlist Sound Device device 'snd_nl': Alias R2.2 was resolved to be terminal R2.2. Terminal R2.2 was not found.

Caught unhandled class netlist::nl_exception exception: Alias R2.2 was resolved to be terminal R2.2. Terminal R2.2 was not found.

The macro expansion is being messed up leading to bogus terminal names:
RES(R2, RES_K(10)) -> R2, ((10) * 1e3).2
CAP(C4, CAP_U(0.005)) -> C4, ((0.005) * 1e-6).2

@couriersud
Copy link
Contributor

@firewave: Thanks for identifying the source of all evil :-)

Actually, CAP(C4, CAP_U(0.005)) should expand to

setup.register_devx("CAP", { "C4", "((0.005) * 1e-6)" });

Now, on getting there, PSTRINGIFY_VA (putil.h) is called. This uses var args heavily.
According to
https://stackoverflow.com/questions/9183993/msvc-variadic-macro-expansion
or
https://stackoverflow.com/questions/48710758/how-to-fix-variadic-macro-related-issues-with-macro-overloading-in-msvc-mic
microsoft c++ has a bug expanding var arg arguments.

Note to myself: The second link has a workaround for vs compilers for counting args. Hopefully it is
possible to develop a VS compatible version of PSTRINGY_VA. Godbolt.org has support for VS2017, so testing should be possible.

@couriersud
Copy link
Contributor

The PSTRINGIFY section in putil.h should be changed to something like the following for MSVC compilers:

#define PSTRINGIFY_HELP(y) # y
#define PSTRINGIFY(x) PSTRINGIFY_HELP(x)

#define PMSVC_BUG(MACRO, ARGS) MACRO ARGS  // name to remind that bug fix is due to MSVC :-)

#define PNARGS_2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, N, ...) N

#define PNARGS_1(...) PMSVC_BUG(PNARGS_2, (__VA_ARGS__))
#define PNARGS(...) PNARGS_1(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)

#define PCONCAT_(a, b) a ## b
#define PCONCAT(a, b) PCONCAT_(a, b)

#define PSTRINGIFY_1(x)                     #x
#define PSTRINGIFY_2(x, x2)                 #x, #x2
#define PSTRINGIFY_3(x, ...)                #x, PSTRINGIFY_2(__VA_ARGS__)
#define PSTRINGIFY_4(x, ...)                #x, PSTRINGIFY_3(__VA_ARGS__)
#define PSTRINGIFY_5(x, ...)                #x, PSTRINGIFY_4(__VA_ARGS__)
#define PSTRINGIFY_6(x, ...)                #x, PSTRINGIFY_5(__VA_ARGS__)
#define PSTRINGIFY_7(x, ...)                #x, PSTRINGIFY_6(__VA_ARGS__)
#define PSTRINGIFY_8(x, ...)                #x, PSTRINGIFY_7(__VA_ARGS__)
#define PSTRINGIFY_9(x, ...)                #x, PSTRINGIFY_8(__VA_ARGS__)
#define PSTRINGIFY_10(x, ...)               #x, PSTRINGIFY_9(__VA_ARGS__)
#define PSTRINGIFY_11(x, ...)               #x, PSTRINGIFY_10(__VA_ARGS__)
#define PSTRINGIFY_12(x, ...)               #x, PSTRINGIFY_11(__VA_ARGS__)
#define PSTRINGIFY_13(x, ...)               #x, PSTRINGIFY_12(__VA_ARGS__)
#define PSTRINGIFY_14(x, ...)               #x, PSTRINGIFY_13(__VA_ARGS__)
#define PSTRINGIFY_15(x, ...)               #x, PSTRINGIFY_14(__VA_ARGS__)
#define PSTRINGIFY_16(x, ...)               #x, PSTRINGIFY_15(__VA_ARGS__)

#define PSTRINGIFY_VA(...) PMSVC_BUG(PCONCAT, (PSTRINGIFY_, PNARGS(__VA_ARGS__)))(__VA_ARGS__)

Will only have time for this later this week. The code delivers expected results on godbolt.org for msvc, g++ and clang++ but needs more testing.

@firewave
Copy link
Contributor

firewave commented Jan 7, 2020

Compiles and no more validation failures.

couriersud added a commit that referenced this issue Jan 8, 2020
Workaround for a bug in msvc. __VA_ARGS__ are expanded to a single token
in msvc, all other compilers expand to a list of tokens.
@couriersud
Copy link
Contributor

Fixed by 7b695da

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

3 participants