rncbc / qsynth

Qsynth - A fluidsynth Qt GUI Interface
https://qsynth.sourceforge.io
GNU General Public License v2.0
66 stars 17 forks source link

Windows: runtime error (assertion failed) in qsynth compiled with MSVC #39

Closed pedrolcl closed 3 years ago

pedrolcl commented 3 years ago

When testing qsynth compiled with the MSVC++ compiler, pressing the "setup..." button throws this message box and dies:

qsynth_runtime_error_20210410

It is the same problem documented here: https://docs.microsoft.com/en-us/answers/questions/240332/assert-when-using-mtd-dynamic-library.html

The problem comes because qsynth and Qt are linked to the DLL C runtime (dynamic runtime, flag /MD) but fluidsynth is linked with the static C runtime library, flag /MT).

The solution is to compile everything using dynamic or static C runtime library, but not mixing both. The easiest fix is to modify fluidsynth CMake buildsystem to make use of the DLL C runtime, because rebuilding each Qt version with the static C runtime is very time consuming.

This is the relevant part of fluidsynth's CMakeList.txt

  if  ( MSVC )
    # statically link in the CRT library to avoid a bunch of runtime DLL dependencies and allow 
    # the CI windows builds to be run under WinXP
#    foreach ( flag_var
#        CMAKE_C_FLAGS
#        CMAKE_C_FLAGS_DEBUG
#        CMAKE_C_FLAGS_RELEASE
#        CMAKE_C_FLAGS_MINSIZEREL
#        CMAKE_C_FLAGS_RELWITHDEBINFO
#        CMAKE_CXX_FLAGS
#        CMAKE_CXX_FLAGS_DEBUG
#        CMAKE_CXX_FLAGS_RELEASE
#        CMAKE_CXX_FLAGS_MINSIZEREL
#        CMAKE_CXX_FLAGS_RELWITHDEBINFO
#        )
#      if ( ${flag_var} MATCHES "/MD" )
#        string ( REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}" )
#      endif ( ${flag_var} MATCHES "/MD" )
#    endforeach ( flag_var )

I will request to add a new configurable option to fluidsynth. Meanwhile, lets keep this ticket as a remainder.

pedrolcl commented 3 years ago

After merging PR #40 and FluidSynth/fluidsynth/pull/848 this issue can be closed now