View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0030516 | Community | OCCT:Visualization | public | 2019-02-23 05:43 | 2019-09-21 10:04 |
Reporter | daidalos77 | Assigned To | bugmaster | ||
Priority | normal | Severity | crash | ||
Status | closed | Resolution | fixed | ||
Platform | Windows | OS | VC++ 2015 | ||
Product Version | 6.8.0 | ||||
Target Version | 7.4.0 | Fixed in Version | 7.4.0 | ||
Summary | 0030516: Visualization - Pointer to an OpenGl_Structure is deleted and accessed later after PrsMgr_Presentation::Highlight() | ||||
Description | When 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 | ||||
Tags | No tags attached. | ||||
Test case number | Not required | ||||
related to | 0030491 | new | nds | Open CASCADE | Visualization - OpenGl_Element inherits Standard_Transient |
related to | 0024307 | closed | apn | Open CASCADE | TKOpenGl - efficient culling of large number of presentations |
related to | 0030989 | new | Open CASCADE | Visualization - heap-use-after-free reported by Clang address sanitizer in OpenGl_Structure::IsRaytracable() | |
child of | 0030557 | new | dpasukhi | Open CASCADE | Coding - eliminate errors reported by -fsanitize |
|
Branch CR30516 has been created by tizmaylo. SHA-1: cfd94674d3017fbd9b169b13752270f331f31412 Detailed log of new commits: Author: tizmaylo Date: Wed Mar 20 11:40:30 2019 +0300 0030516: Pointer to an OpenGl_Structure is deleted and accessed later The flag OpenGl_Structure::IsForHighlight is set to false before erasing of an OpenGl_Structure entity to prevent occurence of dead pointers to it in OpenGl_Layer::myBVHPrimitives. |
|
Branch CR30516_1 has been created by kgv. SHA-1: c4a638db268d4232e94d0d6f43723a23a5562ca5 Detailed log of new commits: Author: kgv Date: Thu May 2 16:58:06 2019 +0300 0030516: Visualization - Pointer to an OpenGl_Structure is deleted and accessed later after PrsMgr_Presentation::Highlight() Do not set IsForHighlight flag for already displayed presentation. |
|
The problem cause is PrsMgr_Presentation::Highlight() -> PrsMgr_Presentation::display(true) setting IsForHighlight flag for already displayed (but hidden) Structure, which makes no sense. In the following script Wireframe presentation is hidden (but already in BVH tree for frustum culling, hence no use to remove it from there) and revealed by selection:pload MODELING VISUALIZATION box b 1 2 3 vclear vinit View1 vdisplay b vfit vsetdispmode b 1 vmoveto 250 250 vselect 250 250 There is a general issue though - when highlighted structure was not displayed, IsForHighlight flag results in no frustum culling for it. Consider selection of entire scene with local selection turned ON (which is unfortunate scenario anyway), it will lead to a lot of structures being not frustum culled. This is a subject for another issue though: pload MODELING VISUALIZATION box b 1 2 3 vclear vinit View1 vdisplay b vfit vsetdispmode b 1 vselmode b FACE 1 vmoveto 250 250 vselect 250 250 |
|
Patch is ready for review. http://jenkins-test-12.nnov.opencascade.com:8080/view/CR30516_1-master-KGV/ |
|
Patch CR30516_1 was reviewed without remarks |
|
Fix has been tested in framework of WEEK-20 branch Combination - OCCT branch : WEEK-20 master SHA - 853af31fb14e2140d821c7ba1c5c5977072d7662 d67d4b811012eef8913d3c535c29654d0acf3c4c Products branch : WEEK-20 SHA - bde66da19002bfd6a68440a079d00728c5796b30 was compiled on Linux, MacOS and Windows platforms and tested in optimize mode. Number of compiler warnings: No new/fixed warnings Regressions/Differences/Improvements: No regressions/differences CPU differences: Debian80-64: OCCT Total CPU difference: 16362.230000000052 / 16346.709999999983 [+0.09%] Products Total CPU difference: 10506.300000000043 / 10516.200000000064 [-0.09%] Windows-64-VC14: OCCT Total CPU difference: 17708.015625 / 17692.25 [+0.09%] Products Total CPU difference: 12195.578125 / 12107.796875 [+0.72%] Image differences : No differences that require special attention Memory differences : No differences that require special attention |
|
Branch CR30516_1 has been deleted by inv. SHA-1: c4a638db268d4232e94d0d6f43723a23a5562ca5 |
|
Branch CR30516 has been deleted by inv. SHA-1: cfd94674d3017fbd9b169b13752270f331f31412 |
occt: master 49dfdb7a 2019-05-02 13:58:06 Committer: bugmaster Details Diff |
0030516: Visualization - Pointer to an OpenGl_Structure is deleted and accessed later after PrsMgr_Presentation::Highlight() Do not set IsForHighlight flag for already displayed presentation. |
Affected Issues 0030516 |
|
mod - src/PrsMgr/PrsMgr_Presentation.cxx | Diff File |
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 |
2019-03-20 11:49 | git | Note Added: 0083132 | |
2019-03-20 11:56 |
|
Assigned To | tizmaylo => kgv |
2019-03-20 11:56 |
|
Status | assigned => resolved |
2019-03-20 11:56 |
|
Steps to Reproduce Updated | |
2019-03-20 12:05 |
|
Assigned To | kgv => tizmaylo |
2019-03-20 12:06 |
|
Steps to Reproduce Updated | |
2019-03-20 12:09 |
|
Assigned To | tizmaylo => kgv |
2019-03-21 14:35 | kgv | Summary | Pointer to an OpenGl_Structure is deleted and accessed later => Visualization - Pointer to an OpenGl_Structure is deleted and accessed later |
2019-05-02 17:02 | kgv | Product Version | 7.2.0 => 6.8.0 |
2019-05-02 17:03 | kgv | Status | resolved => assigned |
2019-05-02 17:03 | kgv | Summary | Visualization - Pointer to an OpenGl_Structure is deleted and accessed later => Visualization - Pointer to an OpenGl_Structure is deleted and accessed later after PrsMgr_Presentation::Highlight() |
2019-05-02 17:06 | git | Note Added: 0084103 | |
2019-05-02 17:21 | kgv | Note Added: 0084104 | |
2019-05-02 19:19 | kgv | Note Added: 0084105 | |
2019-05-02 19:19 | kgv | Assigned To | kgv => san |
2019-05-02 19:19 | kgv | Status | assigned => resolved |
2019-05-07 09:16 | kgv | Assigned To | san => osa |
2019-05-08 10:50 |
|
Note Added: 0084237 | |
2019-05-08 10:50 |
|
Assigned To | osa => bugmaster |
2019-05-08 10:50 |
|
Status | resolved => reviewed |
2019-05-15 12:00 | bugmaster | Note Added: 0084359 | |
2019-05-15 12:00 | bugmaster | Status | reviewed => tested |
2019-05-15 12:01 | bugmaster | Test case number | => Not required |
2019-05-19 10:40 | bugmaster | Changeset attached | => occt master 49dfdb7a |
2019-05-19 10:40 | bugmaster | Status | tested => verified |
2019-05-19 10:40 | bugmaster | Resolution | open => fixed |
2019-05-19 10:54 | git | Note Added: 0084451 | |
2019-05-19 10:54 | git | Note Added: 0084454 | |
2019-09-21 10:04 | kgv | Relationship added | related to 0030989 |
2019-09-21 10:04 | kgv | Relationship added | child of 0030557 |