Crash in 64 bit windows creating DocumentWindow

The same code which runs great on Linux (64 bit) is failing to run on Windows (64 bit, mingw)

Using the very latest JUCE from git, it is crashing simply when I try to create a subclass of DocumentWindow (and it is crashing within the DocumentWindow constructor)

This is the backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004369fc in juce::Component::internalRepaintUnchecked (this=0x4633a30, area=..., isEntireComponent=true)
    at ../../JuceLibraryCode/modules/juce_gui_basics/components/juce_Component.cpp:1935
1935    {
(gdb) bt
#0  0x00000000004369fc in juce::Component::internalRepaintUnchecked (this=0x4633a30, area=..., isEntireComponent=true)
    at ../../JuceLibraryCode/modules/juce_gui_basics/components/juce_Component.cpp:1935
#1  0x0000000000436f7d in juce::Component::repaint (this=0x4633a30)
    at ../../JuceLibraryCode/modules/juce_gui_basics/components/juce_Component.cpp:1907
#2  0x000000000043aa20 in juce::Component::setOpaque (this=this@entry=0x4633a30, shouldBeOpaque=shouldBeOpaque@entry=true)
    at ../../JuceLibraryCode/modules/juce_gui_basics/components/juce_Component.cpp:795
#3  0x000000000046fc80 in juce::TopLevelWindow::TopLevelWindow (this=this@entry=0x4633a30, name=...,
    at ../../JuceLibraryCode/modules/juce_gui_basics/windows/juce_TopLevelWindow.cpp:142
#4  0x000000000047002b in juce::ResizableWindow::ResizableWindow (this=this@entry=0x4633a30, name=...,
    backgroundColour_=backgroundColour_@entry=..., addToDesktop_=addToDesktop_@entry=true)
    at ../../JuceLibraryCode/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp:46
#5  0x000000000047019a in juce::DocumentWindow::DocumentWindow (this=0x4633a30, title=..., backgroundColour=...,
    requiredButtons_=7, addToDesktop_=true) at ../../JuceLibraryCode/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp:58
#6  0x000000000053ddc1 in MyWindow::MyWindow (this=0x4633a30, g=0x4d400b0, name=..., bg=..., requiredButtons=7)
    at src/juce.cpp:498

The code which elicits this response is simple (and works on Linux):

gui->handle = new MyWindow(gui, title, Colour(bg), 7) ; 

"title", "bg" and "7" are passed to the DocumentWindow constructor.

The code also worked fine (in prior JUCE) on Windows 32 bit, but I can't currently compile the 32-bit Windows (as mentioned elsewhere)


Any ideas?

Looks like some kind of linker error to me, not an actual bug in the code. Or something you're doing in your subclass that luckily doesn't crash in other compilers.

But if you're using mingw 64 then I'm afraid you're off-piste, I'm afraid - I've never even tried that myself.

I was afraid you would say something like that.  

The link doesn't complain about anything; could there perhaps  be an issue with link-order? Some weird C++ issue?

Maybe linking mis-matched versions of the headers + cpps? Or mingw64 being broken. Sorry, but I think you're on your own figuring that one out!

OK, I'm not proud of what I've done, but it might help others with this problem.

After getting my application working 100% on all platforms *except* Win 64, I decided to really try to understand the problem. Turns out the cause is quite simple:  mingw64 pulls function parameters (in some cases, not always) using the SSE instruction MOVAPS.  That would be just fine if it also ensured the stack was 16-byte aligned always.  But of course, it doesn't, hence the crashing problem.

As it happens, this is a known problem.  For years.  <sigh>

My solution, which is so geeky-ugly I am embarrassed to admit to it, is to use 'gcc -S' to output assembly, use 'sed' to convert "movaps" to "movups" (the unaligned version of the same instruction), and then use 'as' to assemble the resultant code.

It works perfectly after this, though I feel dirty now...