OpenGL Multisampling Build Error

Hi,

I’ve run into an issue using Multisampling pixel format on windows builds. The error does not occur if I omit the line:

        glContext.setPixelFormat (pf);

I’ve made a simplified example to show the issue; here is the renderer class:

class OpenGLRenderer : public juce::Component, 
                       private juce::OpenGLRenderer, 
                       private juce::Timer
{
public:
    OpenGLRenderer()
    {
#ifdef JUCE_MAC
        glContext.setOpenGLVersionRequired (juce::OpenGLContext::OpenGLVersion::openGL4_1);
#else
        glContext.setOpenGLVersionRequired (juce::OpenGLContext::OpenGLVersion::defaultGLVersion);
#endif
        glContext.setRenderer (this);       
    
        juce::OpenGLPixelFormat pf;
        pf.multisamplingLevel = 4;
        glContext.setPixelFormat (pf);
        glContext.setMultisamplingEnabled (true);
        glContext.setComponentPaintingEnabled(false);
        glContext.attachTo (*this);
        startTimerHz (60);
    }
    ~OpenGLRenderer() override { glContext.detach(); }
    void resized() override { bounds = getLocalBounds(); }
private:
    juce::OpenGLContext glContext;
    juce::CriticalSection mutex;
    juce::Rectangle<int> bounds;

    void timerCallback() override { glContext.triggerRepaint(); }
    void newOpenGLContextCreated() override {}
    void renderOpenGL() override 
    {
        const juce::ScopedLock lock (mutex);
        juce::OpenGLHelpers::clear (getLookAndFeel().findColour (juce::DocumentWindow::backgroundColourId));
        juce::gl::glClear (juce::gl::GL_COLOR_BUFFER_BIT | juce::gl::GL_DEPTH_BUFFER_BIT);
        auto desktopScale = static_cast<float> (glContext.getRenderingScale());
        juce::gl::glDepthFunc (juce::gl::GL_LESS);
        juce::gl::glEnable (juce::gl::GL_MULTISAMPLE);
        
        juce::gl::glViewport (0, 0, 
                              juce::roundToInt(desktopScale * static_cast<float>(bounds.getWidth())), 
                              juce::roundToInt(desktopScale * static_cast<float>(bounds.getHeight())));   
    }
    void openGLContextClosing() override {}
};

The build error happens on Windows but not Mac. When Debugging, the error reported is:

Exception has occurred: The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

This error is reported on line 155 of juce_OpenGLHelpers.cpp. Here is a minimal repo that recreates the issue: GitHub - aaronaanderson/JUCE_OpenGL_MultisampleTest: A bare-bones test to replicate multisampling bug

Has anybody else run into this? Any help would be appreciated; my render looks pretty gnarly without antialiasing. Please let me know if I should provide additional detail.

I got to the bottom of this. The issue was that I was compiling (accidentally) with amd64_x86 instead of amd64. Not sure why this would only be a problem with OpenGL pixel formats and not anything else. I’ll leave the post here in case somebody runs into the same issue in the future.