OpenGl_GraphicDriver, FAILED to release OpenGL context,EGL, eglTerminate FAILED

Hi Forum,
I established a docker, the system version show as follows:
Linux version 3.10.0-1160.45.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ), SMP Wed Oct 13 17:20:51 UTC 2021
CentOS Linux release 8.4.2105.

The Graphicscard infomation show as follows:
00:08.0 VGA compatible controller: Microsoft Corporation Hyper-V virtual VGA

The OpenGL information show as follows:
 

GLvendor: Mesa/X.org
GLdevice: llvmpipe (LLVM 12.0.0, 256 bits)
GLversion: OpenGL ES 3.2 Mesa 21.1.5
GLSLversion: OpenGL ES GLSL ES 3.20
Max texture size: 16384
Max FBO dump size: 16384x16384
Max combined texture units: 192
Max MSAA samples: 4
Viewport: 640x480
ResolutionRatio: 1

I installed OpenCascade7.5.0 in the docker.
I try to dump png from step file in docker and it works, the png is exactly what I want, but the code gives the following error:
 

OpenGl_GraphicDriver, FAILED to release OpenGL context
OpenGl_GraphicDriver, EGL, eglTerminate FAILED

#0  0x00007f0b000c5f0c in malloc_consolidate (av=av@entry=0x7f0b00403bc0 <main_arena>) at malloc.c:4487
#  0x00007f0b000c73c0 in _int_free (av=0x7f0b00403bc0 <main_arena>, p=0x109c2c0, have_lock=<optimized out>) at malloc.c:4412
#2  0x00007f0b0491a625 in NCollection_BaseMap::Destroy(void (*)(NCollection_ListNode*, opencascade::handle<NCollection_BaseAllocator>&), bool) ()
    at /opt/pera_simulator2/Occ/opencascade-7.5.0/install/lib/libTKernel.so.7
#3  0x00007f0b0591420b in OpenGl_GraphicDriver::~OpenGl_GraphicDriver() () at /opt/pera_simulator2/Occ/opencascade-7.5.0/install/lib/libTKOpenGl.so.7
#4  0x00007f0b059143c9 in OpenGl_GraphicDriver::~OpenGl_GraphicDriver() () at /opt/pera_simulator2/Occ/opencascade-7.5.0/install/lib/libTKOpenGl.so.7
#5  0x000000000040e59c in opencascade::handle<OpenGl_GraphicDriver>::EndScope()
    (this=0x6143b8 <makePngByV3d(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, opencascade::handle<Message_Messenger>, int, int, double, double, char const*)::aGraphicDriver>) at /opt/pera_simulator2/Occ/opencascade-7.5.0/install/include/opencascade/Standard_Handle.hxx:394
#6  0x000000000040d5c2 in opencascade::handle<OpenGl_GraphicDriver>::~handle()
    (this=0x6143b8 <makePngByV3d(char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, opencascade::handle<Message_Messenger>, int, int, double, double, char const*)::aGraphicDriver>, __in_chrg=<optimized out>) at /opt/pera_simulator2/Occ/opencascade-7.5.0/install/include/opencascade/Standard_Handle.hxx:84
#7  0x00007f0b0007db0c in __run_exit_handlers (status=0, listp=0x7f0b00403758 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108
#8  0x00007f0b0007dc40 in __GI_exit (status=<optimized out>) at exit.c:139
#9  0x00007f0b0006749a in __libc_start_main (main=0x40b20f <main(int, char**)>, argc=3, argv=0x7fff9ae03768, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fff9ae03758)
    at ../csu/libc-start.c:348
#10 0x000000000040628e in _start ()

Here is my main code:
 

        Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
        static Handle(OpenGl_GraphicDriver) aGraphicDriver;
        if (aGraphicDriver.IsNull()) {
            aGraphicDriver = new OpenGl_GraphicDriver(aDispConnection);
        }
        
        Handle(V3d_Viewer) aViewer = new V3d_Viewer(aGraphicDriver);

        Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(aViewer);
        if (aContext.IsNull()) {
            return 1;
        }

        Handle(V3d_View) aView = aViewer->CreateView();
        if (aView.IsNull()) {
            return 1;
        }
        Handle(Xw_Window) aWindow = new Xw_Window(aContext->CurrentViewer()->Driver()->GetDisplayConnection(), "V3d", 0, 0, a, b);
        aWindow->SetVirtual(Standard_True);
        aView->SetWindow(aWindow);
        if (!aWindow->IsMapped()) {
            aWindow->Map();
        }

        aViewer->SetDefaultBackgroundColor(Quantity_Color(0.9, 0.9, 0.9, Quantity_TOC_RGB));
        aViewer->SetLightOn();
        aViewer->SetDefaultLights();
        aViewer->SetComputedMode(false);

        aViewer->SetViewOn(aView);
        Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
        aParams.Method = Graphic3d_RM_RASTERIZATION;
        aParams.RaytracingDepth = 3;
        aParams.IsShadowEnabled = true;
        aParams.IsReflectionEnabled = true;
        aParams.IsAntialiasingEnabled = true;
        aParams.IsTransparentShadowEnabled = false;
        aParams.ToReverseStereo = true;
        aParams.StereoMode = Graphic3d_StereoMode::Graphic3d_StereoMode_QuadBuffer;
        aParams.AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph::Anaglyph_RedCyan_Optimized;
        aParams.FrustumCullingState = Graphic3d_RenderingParams::FrustumCulling::FrustumCulling_On;
        aParams.LineFeather = 1.0;
        aParams.NbMsaaSamples = 4;
        aView->Redraw();
        aView->Size(Width, Height);
        aView->SetBackgroundColor(Quantity_TOC_RGB, 0.8, 0.8, 0.8);
        aView->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
        aView->SetImmediateUpdate(Standard_False);
        Handle(AIS_Shape) aColoredShape = new AIS_Shape(shape);
        aColoredShape->SetWidth(10.0);
        aColoredShape->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_NEON_GNC));
        aContext->SetColor(aColoredShape, Quantity_Color(0.2, 0.2, 0.2, Quantity_TOC_RGB), false);
        aContext->SetDisplayMode(AIS_Shaded, true);
        aContext->Display(aColoredShape, false);
        aView->FitAll();
        aView->Redraw();
        if (aView.IsNull()) {
            return 1;
        }
        string pngname = path + "/thumb.png";
        char pngfile[300];
        strcpy(pngfile, pngname.c_str());
        Standard_Boolean ok = aView->Dump(pngfile, Graphic3d_BT_RGB);

Does anyone know how to solve this problem?

Kirill Gavrilov's picture

I don't have Docker, but your sample doesn't crash for me in VirtualBox 18.04 and OCCT 7.6.0.
How do you setup X11 server in your case?
Have you tried OCCT 7.6.0?

#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <Aspect_DisplayConnection.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <OSD.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <Xw_Window.hxx>

#include <string>

int main (int theNbArgs, char* theArgVec[])
{
  OSD::SetSignal (false);
  OSD::SetSignalStackTraceLength (10);

    Handle(Aspect_DisplayConnection) aDispConnection = new Aspect_DisplayConnection();
    static Handle(OpenGl_GraphicDriver) aGraphicDriver;
    if (aGraphicDriver.IsNull()) {
        aGraphicDriver = new OpenGl_GraphicDriver(aDispConnection);
    }
    
    Handle(V3d_Viewer) aViewer = new V3d_Viewer(aGraphicDriver);

    Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(aViewer);
    if (aContext.IsNull()) {
        return 1;
    }

    Handle(V3d_View) aView = aViewer->CreateView();
    if (aView.IsNull()) {
        return 1;
    }

    int a = 512, b = 512;
    Handle(Xw_Window) aWindow = new Xw_Window(aContext->CurrentViewer()->Driver()->GetDisplayConnection(), "V3d", 0, 0, a, b);
    aWindow->SetVirtual(Standard_True);
    aView->SetWindow(aWindow);
    if (!aWindow->IsMapped()) {
        aWindow->Map();
    }

    aViewer->SetDefaultBackgroundColor(Quantity_Color(0.9, 0.9, 0.9, Quantity_TOC_RGB));
    aViewer->SetLightOn();
    aViewer->SetDefaultLights();
    aViewer->SetComputedMode(false);

    aViewer->SetViewOn(aView);
    Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
    aParams.Method = Graphic3d_RM_RASTERIZATION;
    aParams.RaytracingDepth = 3;
    aParams.IsShadowEnabled = true;
    aParams.IsReflectionEnabled = true;
    aParams.IsAntialiasingEnabled = true;
    aParams.IsTransparentShadowEnabled = false;
    aParams.ToReverseStereo = true;
    aParams.StereoMode = Graphic3d_StereoMode::Graphic3d_StereoMode_QuadBuffer;
    aParams.AnaglyphFilter = Graphic3d_RenderingParams::Anaglyph::Anaglyph_RedCyan_Optimized;
    aParams.FrustumCullingState = Graphic3d_RenderingParams::FrustumCulling::FrustumCulling_On;
    aParams.LineFeather = 1.0;
    aParams.NbMsaaSamples = 4;
    aView->Redraw();
    double Width = 9, Height = 0;
    aView->Size(Width, Height);
    aView->SetBackgroundColor(Quantity_TOC_RGB, 0.8, 0.8, 0.8);
    aView->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Orthographic);
    aView->SetImmediateUpdate(Standard_False);

    TopoDS_Shape shape = BRepPrimAPI_MakeBox (50, 50, 75);
    Handle(AIS_Shape) aColoredShape = new AIS_Shape(shape);
    aColoredShape->SetWidth(10.0);
    aColoredShape->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_NEON_GNC));
    aContext->SetColor(aColoredShape, Quantity_Color(0.2, 0.2, 0.2, Quantity_TOC_RGB), false);
    aContext->SetDisplayMode(AIS_Shaded, true);
    aContext->Display(aColoredShape, false);
    aView->FitAll();
    aView->Redraw();
    if (aView.IsNull()) {
        return 1;
    }

    std::string path = ".";
    std::string pngname = path + "/thumb.png";
    char pngfile[300];
    strcpy(pngfile, pngname.c_str());
    Standard_Boolean ok = aView->Dump(pngfile, Graphic3d_BT_RGB);
        
  return 0;
}
li hanming's picture

I have already set X11 server in my case.
And I installed opencascade7.6.0 instead of old one in the same docker, it works!
Thank you Kirill, now it is working properly!