Crash in Ogre 2.1 with OpenGL3

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


JobMulderXsens
Gnoblar
Posts: 5
Joined: Thu Nov 27, 2025 1:01 pm

Crash in Ogre 2.1 with OpenGL3

Post by JobMulderXsens »

I have a crash in Ogre 2.1.2 (and 2.1.0) when using the OpenGL3Plus renderer.

This is for an existing Qt application, which has been running with Ogre-next 2.1.0 on Windows using DX11 for many years. Recently it was decided to port this to Linux and due to some time constraints upgrading to the latest Ogre is not a practical solution.

The port went fine, Ogre wants to start, assets are loaded, we get a window, etc, but during the first 'renderOneFrame' it crashes in HlmsPbsDatablock::uploadToConstBuffer during the memcpy at (for me) line 438.

My function code, for reference:

Code: Select all

    //-----------------------------------------------------------------------------------
    void HlmsPbsDatablock::uploadToConstBuffer( char *dstPtr )
    {
        _padding0 = mAlphaTestThreshold;
        float oldFresnelR = mFresnelR;
        float oldFresnelG = mFresnelG;
        float oldFresnelB = mFresnelB;

    float oldkDr = mkDr;
    float oldkDg = mkDg;
    float oldkDb = mkDb;

    if( mTransparencyMode == Transparent )
    {
        //Precompute the transparency CPU-side.
        if( mWorkflow != MetallicWorkflow )
        {
            mFresnelR *= mTransparencyValue;
            mFresnelG *= mTransparencyValue;
            mFresnelB *= mTransparencyValue;
        }
        mkDr *= mTransparencyValue * mTransparencyValue;
        mkDg *= mTransparencyValue * mTransparencyValue;
        mkDb *= mTransparencyValue * mTransparencyValue;
    }

    memcpy( dstPtr, &mBgDiffuse[0], MaterialSizeInGpu ); /* here I get a segmentation fault */

    mkDr = oldkDr;
    mkDg = oldkDg;
    mkDb = oldkDb;

    mFresnelR = oldFresnelR;
    mFresnelG = oldFresnelG;
    mFresnelB = oldFresnelB;
}

It seems similar to viewtopic.php?p=516097&sid=3349cb708aa2 ... e6#p516097 but I don't know if it is the same issue.
On Windows with DX11 everything works fine, so I suspect something OpenGL3+ specific.

The scene is not very complex, but we do have multiple lights, some of which are not shadow casting, but being used for lighting the backside of objects as well as ambient lighting.

Since the same issue occurs on both KUbuntu 25.10 (Ogre 2.1.2) and Windows 11 (Ogre 2.1.0, OpenGL3Plus), but not on Windows 11 (Ogre 2.1.0 DX11), I suspect it is not a driver issue.
Unfortunately the scene is not easily shareable, so I cannot provide a minimal test case.

I did enable ENABLE_GL_CHECK in OgreGL3PlusPrerequisites.h as per the snippet below at line 112.

Code: Select all

#define ENABLE_GL_CHECK 1

This resulted in an exception being thrown in GL3PlusVaoManager::waitFor around line 1260:

Code: Select all

            if( waitRet == GL_WAIT_FAILED )
            {
                OGRE_EXCEPT( Exception::ERR_RENDERINGAPI_ERROR,
                             "Failure while waiting for a GL Fence. Could be out of GPU memory. "
                             "Update your video card drivers. If that doesn't help, "
                             "contact the developers.",
                             "GL3PlusVaoManager::getDynamicBufferCurrentFrame" );

            return fenceName;
        }

This seems to indicate a GPU memory issue, but as I said, it works fine with DX11 and the scene is not very complex, it's just built up through lots of dynamic code. It's basically this scene: https://www.movella.com/hs-fs/hubfs/Ima ... 3)-1-1.png

When I'm not actively rendering, but the Ogre Root window exists, I can see the dynamic buffer cycling through 3 temporary buffers (as expected, since mDynamicBufferMultiplier is 3) and the fences being created and deleted as expected. But when rendering starts, the crash happens almost immediately.

Any ideas on how to further trace or fix this issue are very welcome.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5539
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1399

Re: Crash in Ogre 2.1 with OpenGL3

Post by dark_sylinc »

OgreNext 2.1 is EOL.

But in spirit of helping: You forgot to post your GPU and driver version (very important) and Ogre.log

Aside from that there are more things that are worth checking out:

  1. OpenGL requires a "main window", if at some point you destroyed all windows, or try to use Ogre without a window, it will malfunction heavily, likely turn into a crash. Our D3D11 implementation is a lot more lenient on that because D3D11 does not require one. One workaround to this issue is to create a 4x4 window at startup and hide it. Then keep that window around for the lifetime of your application.
  2. 3D API calls must not be made from multiple threads. This applies to both D3D11 and GL, but D3D11 it may "just work" out of luck (it's still risky), while in OpenGL it will turn into a hard crash. Make sure all 3D API calls happen from the main thread.
  3. OpenGL has the concept of "current context". If a third party (like Qt) un/sets a different context, it will break OgreNext. You can retrieve GLXContext via GLXWindow::getCustomAttribute("GLCONTEXT") then manually call GL3PlusContext::setCurrent() after Qt relinquishes control and before OgreNext calls start.
JobMulderXsens
Gnoblar
Posts: 5
Joined: Thu Nov 27, 2025 1:01 pm

Re: Crash in Ogre 2.1 with OpenGL3

Post by JobMulderXsens »

Thanks for the reply and I am aware that we're using a very old Ogre version. Upgrading something that works, somehow never ends up on top of the todo pile ;) Especially since it's not a trivial upgrade even from 2.1 to 2.2.

  1. We do have a main window that we start and hide at the start of the application also for D3D11. It's a 1x1 window though, so I'll see what happens if I make it a bit bigger.
  2. We have a single thread calling renderOneFrame and we leave all the administrative stuff to Ogre. I expect that if we were doing the threading wrong, the DX11 part would also have failed more in the past 10 years.
  3. I will try the GLCONTEXT tip.

If all that fails, we'll do the update to a more recent version. Any tips on what the best version would be in our situation in terms of "Least effort vs most chance of fixing this problem"?

JobMulderXsens
Gnoblar
Posts: 5
Joined: Thu Nov 27, 2025 1:01 pm

Re: Crash in Ogre 2.1 with OpenGL3

Post by JobMulderXsens »

The 4x4 window didn't change anything and the GLCONTEXT does affect the behaviour:

  • on windows Qt now crashes in some DX interaction
  • on Linux the GL crash still exists but I get more OpenGL errors

Question: Is it ok to add stuff to the scenegraph from other threads when we're not actively rendering or are these errors likely the result of doing that?:

OpenGL error 0x0501 GL_INVALID_VALUE in void Ogre::GL3PlusDepthBuffer::bindToFramebuffer(GLenum) at line 255 for glFramebufferTexture

OpenGL error 0x0506 GL_INVALID_FRAMEBUFFER_OPERATION in virtual void Ogre::GL3PlusRenderSystem::clearFrameBuffer(unsigned int, const Ogre::ColourValue&, Ogre::Real, short unsigned int) at line 3150 for glClear

OpenGL error 0x0501 GL_INVALID_VALUE in void Ogre::GL3PlusDepthBuffer::bindToFramebuffer(GLenum) at line 255 for glFramebufferTexture

OpenGL error 0x0502 GL_INVALID_OPERATION in virtual void Ogre::GL3PlusBufferInterface::unmap(Ogre::UnmapOptions, size_t, size_t) at line 134 for glBindBuffer

OpenGL error 0x0502 GL_INVALID_OPERATION in void Ogre::GL3PlusDynamicBuffer::flush(size_t, size_t, size_t) at line 103 for glFlushMappedBufferRange

OpenGL error 0x0502 GL_INVALID_OPERATION in virtual void* Ogre::GL3PlusStagingBuffer::mapImpl(size_t) at line 204 for mMappedPtr = glMapBufferRange

Sorry for wasting your time on this EOL version. I'm already building the latest version to start the migration, but I was hoping to finish this before the end of the month...

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5539
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1399

Re: Crash in Ogre 2.1 with OpenGL3

Post by dark_sylinc »

on windows Qt now crashes in some DX interaction

You won't get a valid pointer if you ask for GLCONTEXT while using D3D11 RenderSystem.

Question: Is it ok to add stuff to the scenegraph from other threads when we're not actively rendering or are these errors likely the result of doing that?:

Not ok.

Code: Select all

OpenGL error 0x0501 GL_INVALID_VALUE in void Ogre::GL3PlusDepthBuffer::bindToFramebuffer(GLenum) at line 255 for glFramebufferTexture

OpenGL error 0x0506 GL_INVALID_FRAMEBUFFER_OPERATION in virtual void Ogre::GL3PlusRenderSystem::clearFrameBuffer(unsigned int, const Ogre::ColourValue&, Ogre::Real, short unsigned int) at line 3150 for glClear

OpenGL error 0x0501 GL_INVALID_VALUE in void Ogre::GL3PlusDepthBuffer::bindToFramebuffer(GLenum) at line 255 for glFramebufferTexture

OpenGL error 0x0502 GL_INVALID_OPERATION in virtual void Ogre::GL3PlusBufferInterface::unmap(Ogre::UnmapOptions, size_t, size_t) at line 134 for glBindBuffer

OpenGL error 0x0502 GL_INVALID_OPERATION in void Ogre::GL3PlusDynamicBuffer::flush(size_t, size_t, size_t) at line 103 for glFlushMappedBufferRange

OpenGL error 0x0502 GL_INVALID_OPERATION in virtual void* Ogre::GL3PlusStagingBuffer::mapImpl(size_t) at line 204 for mMappedPtr = glMapBufferRange

These look a lot like calling OpenGL from the wrong thread or the GL context is not active/set.

JobMulderXsens
Gnoblar
Posts: 5
Joined: Thu Nov 27, 2025 1:01 pm

Re: Crash in Ogre 2.1 with OpenGL3

Post by JobMulderXsens »

Interestingly, the very same crash also occurs when using Ogre version 3.0.0. So, the topic should be updated?

And in reply to your comments: on Windows I also switched to OpenGL3 to test if it works there (debugging is better on windows). It works fine with DX11, but on windows with OpenGL it fails, also with the GLCONTEXT trickery.

I suspect that the problem is indeed that Qt and Ogre both use OpenGL and interfere with each other. I will try to switch Ogre to Vulkan tomorrow to avoid any conflicts, but I couldn't find an easy to install SDK yet. Any suggestions on where to find it? When I use "apt install libvulkan-dev" it does install, but Ogre's cmake doesn't seem able to find it, so Ogre's build says:

-- The following OPTIONAL packages could NOT be located on your system.
-- Consider installing them to enable more features from this software.

apt list:
libvulkan-dev/questing,now 1.4.321.0-1 amd64 [installed]
libopenvr-dev/questing,now 1.23.7ds1-2.1build2 amd64 [installed]

More configuring and SDK building tomorrrow I guess, thanks for the tips so far :)
Cheers, Job

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5539
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1399

Re: Crash in Ogre 2.1 with OpenGL3

Post by dark_sylinc »

Use ogre-next-deps. It contains all the dependencies you need (incl Vulkan SDK).

The Quick Start scripts already download them by default.

I recommend you try the Quick Start scripts. Even if you don't like those scripts, you can see the commands it is using so later you can do your own thing.

Interestingly, the very same crash also occurs when using Ogre version 3.0.0. So, the topic should be updated?

Gazebo uses Qt + Ogre-Next (both OpenGL and Vulkan, though Vulkan is less tested), and they haven't had issues with it.

For Vulkan, Qt 6.x is highly recommended, and you'll have to see Tutorial_VulkanExternal.cpp so that OgreNext can be initialized using Qt's Vulkan handle.

Try taking a look at how they set it up.

JobMulderXsens
Gnoblar
Posts: 5
Joined: Thu Nov 27, 2025 1:01 pm

Re: Crash in Ogre 2.1 with OpenGL3

Post by JobMulderXsens »

Thanks for all the help, I got it (almost) working with Vulkan. I have visuals, but the render window is not attached to the Qt window yet, but at least it's not crashing at startup anymore and I have some actually rendering stuff.