MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0030516Community[OCCT] OCCT:Visualizationpublic2019-02-23 05:432019-03-14 18:16
Reporterdaidalos77 
Assigned Totizmaylo 
PrioritynormalSeveritycrash 
StatusassignedResolutionopen 
PlatformWindowsOSVC++ 2015OS Version64 bit
Product Version[OCCT] 7.2.0 
Target Version[OCCT] 7.4.0*Fixed in Version 
Summary0030516: Pointer to an OpenGl_Structure is deleted and accessed later
DescriptionWhen creating a 3d shape(g.e. box) and then displaying it and then shading and then hilighting it and last trying to remove it from every viewer a deleted OpenGl_Structure pointer fails to be removed from OpenGl_BVHClipPrimitiveSet::myStructs
Steps To Reproduce#include <AIS_Trihedron.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <Geom_Axis2Placement.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <WNT_Window.hxx>


#pragma comment (lib , "TKernel.lib")
#pragma comment (lib , "TKG3d.lib")
#pragma comment (lib , "TKMath.lib")
#pragma comment (lib , "TKOpenGl.lib")
#pragma comment (lib , "TKPrim.lib")
#pragma comment (lib , "TKService.lib")
#pragma comment (lib , "TKTopAlgo.lib")
#pragma comment (lib , "TKV3d.lib")

Handle( V3d_Viewer ) myViewerEx;
void TestOpenCascade( HWND wnd )
{
    Handle( Graphic3d_GraphicDriver ) defaultGraphicDriver = new OpenGl_GraphicDriver( new Aspect_DisplayConnection() );
    Handle( V3d_Viewer ) myViewer = new V3d_Viewer( defaultGraphicDriver );
    myViewerEx = myViewer;
    Handle( AIS_InteractiveContext ) myContext = new AIS_InteractiveContext( myViewer );
    Handle( V3d_View ) myView = myViewer->CreateView();
    Handle( WNT_Window ) hWNTWnd = new WNT_Window( reinterpret_cast<HWND>(wnd) );
    myView->SetWindow( hWNTWnd );

    myView->SetAutoZFitMode( Standard_True );
    myView->MustBeResized();
    
    Handle( AIS_Trihedron ) myTrihedron = new AIS_Trihedron( new Geom_Axis2Placement( gp::XOY() ) );
    
    myContext->Display( myTrihedron, Standard_False );
    myContext->Deactivate( myTrihedron );//Deactivate selection of trihedron

    TopoDS_Shape aBoxShape = BRepPrimAPI_MakeBox( 100, 100, 100 );
    Handle( AIS_Shape ) myAIS = new AIS_Shape( aBoxShape );
    myContext->Display( myAIS, Standard_True );
    myContext->SetDisplayMode( myAIS, AIS_Shaded, Standard_True );
    myContext->HilightWithColor( myAIS, myContext->HighlightStyle( Prs3d_TypeOfHighlight_Dynamic ), Standard_True );
    myContext->Remove( myAIS, Standard_True );
};
Additional information
and documentation updates
Added trace function to following functions


void trace( const char *format, ... )
{
    va_list args;
    va_start( args, format );

    const int cChars = vsnprintf( NULL, 0, format, args );
    char *pBuffer = new char[cChars + 1]{ '\0' };
    vsnprintf( pBuffer, cChars + 1, format, args );
    ::OutputDebugStringA( pBuffer );
    delete[] pBuffer;
    va_end( args );
}
unsigned int deletemeplsnow = 0, deletemeplsnow2 = 0, deletemeplsnow3 = 0;

OpenGl_Structure::~OpenGl_Structure()
{
  trace( "OpenGl_Structure::~OpenGl_Structure %p\r\n", this );
  Release (Handle(OpenGl_Context)());
}

Graphic3d_BndBox3d OpenGl_BVHClipPrimitiveSet::Box (const Standard_Integer theIdx) const
{
    trace( "OpenGl_BVHClipPrimitiveSet::Box(%d) : %p\r\n", deletemeplsnow2++, myStructs.FindKey( theIdx + 1 ) );
  return myStructs.FindKey (theIdx + 1)->BoundingBox();
}

Standard_Boolean OpenGl_BVHClipPrimitiveSet::Add (const OpenGl_Structure* theStruct)
{
  const Standard_Integer aSize = myStructs.Size();
  trace( "OpenGl_BVHClipPrimitiveSet::Add(%d) : %p\r\n", deletemeplsnow++, theStruct );
  if (myStructs.Add (theStruct) > aSize) // new structure?
  {
    MarkDirty();

    return Standard_True;
  }

  return Standard_False;
}

Standard_Boolean OpenGl_BVHClipPrimitiveSet::Remove (const OpenGl_Structure* theStruct)
{
    trace( "OpenGl_BVHClipPrimitiveSet::Remove(%d) : %p\r\n", deletemeplsnow3++, theStruct );
  const Standard_Integer anIndex = myStructs.FindIndex (theStruct);

  if (anIndex != 0)
  {
    myStructs.Swap (Size(), anIndex);
    myStructs.RemoveLast();
    MarkDirty();

    return Standard_True;
  }

  return Standard_False;
}





RESULT OUTPUT:

OpenGl_BVHClipPrimitiveSet::Add(0) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Add(1) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Box(0) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Add(2) : 0000004F60AACFA0
OpenGl_BVHClipPrimitiveSet::Add(3) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Add(4) : 0000004F60AACFA0
OpenGl_BVHClipPrimitiveSet::Box(1) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Box(2) : 0000004F60AACFA0
OpenGl_BVHClipPrimitiveSet::Box(3) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Box(4) : 0000004F60AACFA0
OpenGl_BVHClipPrimitiveSet::Box(5) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Box(6) : 0000004F60AACFA0
OpenGl_BVHClipPrimitiveSet::Box(7) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Box(8) : 0000004F60AACFA0
OpenGl_BVHClipPrimitiveSet::Box(9) : 0000004F60AACB50
OpenGl_BVHClipPrimitiveSet::Box(10) : 0000004F60AACFA0
OpenGl_Structure::~OpenGl_Structure 0000004F60AACB50 <------deleted
OpenGl_BVHClipPrimitiveSet::Remove(0) : 0000004F60AACFA0
OpenGl_Structure::~OpenGl_Structure 0000004F60AACFA0
OpenGl_BVHClipPrimitiveSet::Box(11) : 0000004F60AACB50 <------accessed
OpenGl_Structure::~OpenGl_Structure 0000004F60AACE30


QUICK AND DIRTY SOLUTION FOR MY CASE JUST BEFORE CALLING REMOVE FUNCTION:


    PrsMgr_Presentations &shapePresentations = myAIS->Presentations();
    for( int i = 0; i < shapePresentations.Length(); ++i )
        shapePresentations.Value( i + 1 ).Presentation()->Presentation()->SetIsForHighlight( false );


myContext->Remove( myAIS, Standard_True );


RESULT OUTPUT:

OpenGl_BVHClipPrimitiveSet::Add(0) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Add(1) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Box(0) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Add(2) : 000000F030FFD5E0
OpenGl_BVHClipPrimitiveSet::Add(3) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Add(4) : 000000F030FFD5E0
OpenGl_BVHClipPrimitiveSet::Box(1) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Box(2) : 000000F030FFD5E0
OpenGl_BVHClipPrimitiveSet::Box(3) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Box(4) : 000000F030FFD5E0
OpenGl_BVHClipPrimitiveSet::Box(5) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Box(6) : 000000F030FFD5E0
OpenGl_BVHClipPrimitiveSet::Box(7) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Box(8) : 000000F030FFD5E0
OpenGl_BVHClipPrimitiveSet::Box(9) : 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Box(10) : 000000F030FFD5E0
OpenGl_BVHClipPrimitiveSet::Remove(0) : 000000F0310376F0
OpenGl_Structure::~OpenGl_Structure 000000F0310376F0
OpenGl_BVHClipPrimitiveSet::Remove(1) : 000000F030FFD5E0
OpenGl_Structure::~OpenGl_Structure 000000F030FFD5E0
OpenGl_Structure::~OpenGl_Structure 000000F030FACB40
TagsNo tags attached.
Test case number
Attached Files

- Relationships
related to 0030491newnds Open CASCADE Visualization - OpenGl_Element inherits Standard_Transient 
related to 0024307closedapn Open CASCADE TKOpenGl - efficient culling of large number of presentations 

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2019-02-23 05:43 daidalos77 New Issue
2019-02-23 05:43 daidalos77 Assigned To => kgv
2019-02-23 13:35 kgv Relationship added related to 0030491
2019-02-23 13:35 kgv Target Version => 7.4.0*
2019-02-23 13:37 kgv Relationship added related to 0024307
2019-03-14 18:16 kgv Assigned To kgv => tizmaylo
2019-03-14 18:16 kgv Status new => assigned


Copyright © 2000 - 2019 MantisBT Team
Powered by Mantis Bugtracker