MantisBT
Mantis Bug Tracker Workflow

View Issue Details Jump to Notes ] Related Changesets ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0023345Community[OCCT] OCCT:Visualizationpublic2012-07-25 13:402012-11-16 13:18
ReporterPawel 
Assigned Tokgv 
PriorityhighSeveritycrash 
StatusclosedResolutionfixed 
PlatformWindowsOSVC++ 2008OS Version32 bit
Product Version[OCCT] 6.5.3 
Target Version[OCCT] 6.5.4Fixed in Version[OCCT] 6.5.4 
Summary0023345: Crash when destroying OpenGl_Element
DescriptionAfter compiling master/origin with the HEAD revision 0023342 my MFC application started crashing (opening and then closing the document/viewer was enough). The crash in my case occurred only when closing the document (the handle to OpenGl_Context was Null).

I discovered that in the issue 023226 "Extend OpenGl_Context to store map of shared GPU resources" some new functionalities were added. One of them causes the crash.

And so, in OpenGl_Element.hxx a new method - Destroy - was added that makes the following call:

theElement->Release (theContext);

However, it is possible that the provided 'const Handle(OpenGl_Context)&' to the context is a Null one and that causes the crash.

My suggestion is to check the context against 'Null' and if it's not the case to call the 'Release' method.

if(theContext.IsNull() == Standard_False)
  theElement->Release (theContext);

The solves the problem in my case.
Steps To ReproduceHere is the reproducer:

1. Compile the MFC samples provided with OCCT using the 0023342 revision of OCCT (origin/master branch)
2. Run the Triangulation sample.
3. Press the "Mesh" button.
4. Exit the application.

This reproduces the problem on my WinXP machine. The application finishes up in the OpenGl_PrimitiveArray::Release (as described in the below section) and crashes because of the Null context handle.

Interesting is, that if nothing is shown (no meshing done) in the application, no problem occurs.
Additional information
and documentation updates
The root problem is caused by the method OpenGl_PrimitiveArray::Release.

In line 1555, the method theContext->DelayedRelease (myVbos[anIter]); holds an Null context-handle and crashes.
TagsNo tags attached.
Test case numberNot needed
Attached Files

- Relationships
related to 0023500closedibs Open CASCADE MFC texture example is crashed when view closed 

-  Notes
(0021147)
Pawel (developer)
2012-07-25 13:52

Corresponding git branch pushed. Please review.
(0021148)
kgv (developer)
2012-07-25 17:37

This is incorrect by design - OpenGl_Element::Destroy() method needed to NEVER forget to release GPU resources. Thus all elements should be explicitly destroyed before OpenGl_Context.

Please provide full sample for your use case to prepare appropriate patch.
(0021151)
Pawel (developer)
2012-07-25 18:51

Thanks for reviewing the issue.

I have provided further information how to reproduce the problem in the issue description/information.

Hope this helps.
(0021195)
Pawel (developer)
2012-08-01 11:42

Just a couple of observations, maybe they help.

I have looked at the branch 23345_2 committed by kgv. In that form the samples still crash but with a couple of tweaks the problem seems to be solved:

- CViewer3dView in MFC samples does not inherit from OCC_3dView so that the cleaning code put in ~OCC_3dView() is not actually called. As first step, I put the cleaning code (ProcessLastView) to ~CViewer3dView()
- This solved the problem but only partially. If I run a sample (let's say Viewer3d) create an object (e.g sphere) and close the view everything is OK. But if I hover over an object in the viewer so that it gets highlighted or select it the application crashes closing the viewer.
- To solve this I noticed I had to nullify the handles to AIS_Shapes stored in CViewer3dDoc

Handle_User_Cylinder myCylinder;
Handle_AIS_Shape mySphere;
Handle_AIS_Shape myBox;
Handle_AIS_Shape myOverlappedCylinder;
...

- In that case no crash occurs anymore.

Again, as I don't have much experience with OpenGL I can't say if the root cause of the problem is solved by that but it seems to work.

Hope this helps
Pawel
(0021472)
kgv (developer)
2012-09-13 11:52

One more problem detected - this can be not enough to call
> AIS_InteractiveContext::RemoveAll (Standard_False);
to clean up all Interactive Objects.
There are several StdSelect_ViewerSelector3d instances present in AIS_InteractiveContext which holds SelectMgr_DataMapOfIntegerSensitive (StdSelect_ViewerSelector3d::myentities) and doesn't cleared by AIS_InteractiveContext::RemoveAll() call.

As workaround application may call:
> myAISContext->RemoveAll (Standard_False);
> Handle(StdSelect_ViewerSelector3d) aSel = myAISContext->MainSelector();
> if (!aSel.IsNull())
> {
> aSel->Clear();
> }
> aSel = myAISContext->LocalSelector();
> if (!aSel.IsNull())
> {
> aSel->Clear();
> }
But this extra code looks strange so it is probably better to perform it inside OCCT somehow.
(0021681)
Pawel (developer)
2012-10-08 16:47

I applied the workaround from kgv but still get crashes when working with local context.

The stack looks like this:

04B95320 (TKOpenGl): (filename not available): OpenGl_Context::DelayedRelease
04BAA510 (TKOpenGl): (filename not available): OpenGl_GraphicDriver::TriedronEcho

At the moment I don't have a reproducer (the crash occurs in our software but is 100% reproducible) so this note is for documentation purposes only.
(0021682)
kgv (developer)
2012-10-08 17:41
edited on: 2012-10-08 17:42

2Pawel,

just to clarify - your comment was about CR23345_3 branch?

(0021688)
Pawel (developer)
2012-10-08 18:37

Hello kgv,

1. No, I actually meant your suggestion (0021472) about StdSelect_ViewerSelector3d:

myAISContext->RemoveAll (Standard_False);
Handle(StdSelect_ViewerSelector3d) aSel = myAISContext->MainSelector();
if (!aSel.IsNull())
{
aSel->Clear();
...

2. I haven't noticed the branch CR23345_3 so far. But I have compiled it just right now and it worked!

Thanks for the hint
(0021711)
abv (manager)
2012-10-10 17:53

I propose the current state of CR23345_3 to be tested for integration to 6.5.4 beta, and remaining problems to be treated within a separate issue
(0021778)
mkv (tester)
2012-10-16 10:16

Dear BugMaster,
Branch CR23345_3 (and master from occt-products) was compiled on Linux and Windows platforms and tested.

Regressions:
Not detected

Improvements:
Not detected

Testing cases:
Not needed

- Related Changesets
occt: master dd8a4ce9
Timestamp: 2012-10-12 12:56:23
Author: kgv
Details ] Diff ]
0023345: Crash when destroying OpenGl_Element

OpenGl_PrimitiveArray::Release() - avoid possible NULL-pointer dereference
OpenGl_GraphicDriver::RemoveView() - release GL resources within removing last view
Fixed OCC280 test command - do not remove old view until new one is initialized
mod - src/OpenGl/OpenGl_GraphicDriver_7.cxx Diff ] File ]
mod - src/OpenGl/OpenGl_PrimitiveArray.cxx Diff ] File ]
mod - src/OpenGl/OpenGl_Structure.cxx Diff ] File ]
mod - src/OpenGl/OpenGl_Structure.hxx Diff ] File ]
mod - src/QABugs/QABugs_17.cxx Diff ] File ]

- Issue History
Date Modified Username Field Change
2012-07-25 13:40 Pawel New Issue
2012-07-25 13:40 Pawel Assigned To => Pawel
2012-07-25 13:52 Pawel Note Added: 0021147
2012-07-25 13:52 Pawel Assigned To Pawel => bugmaster
2012-07-25 13:52 Pawel Status new => resolved
2012-07-25 17:20 abv Assigned To bugmaster => kgv
2012-07-25 17:37 kgv Note Added: 0021148
2012-07-25 17:37 kgv Assigned To kgv => Pawel
2012-07-25 17:37 kgv Status resolved => feedback
2012-07-25 18:35 Pawel Additional Information Updated View Revisions
2012-07-25 18:47 Pawel Note Added: 0021150
2012-07-25 18:47 Pawel Status feedback => assigned
2012-07-25 18:47 Pawel Status assigned => feedback
2012-07-25 18:49 Pawel Steps to Reproduce Updated View Revisions
2012-07-25 18:49 Pawel Note Deleted: 0021150
2012-07-25 18:50 Pawel Steps to Reproduce Updated View Revisions
2012-07-25 18:51 Pawel Note Added: 0021151
2012-07-25 18:51 Pawel Status feedback => assigned
2012-07-25 18:51 Pawel Assigned To Pawel => kgv
2012-07-25 18:53 Pawel Steps to Reproduce Updated View Revisions
2012-08-01 10:50 kgv Assigned To kgv => san
2012-08-01 11:42 Pawel Note Added: 0021195
2012-09-13 11:52 kgv Note Added: 0021472
2012-09-14 15:38 san Assigned To san => kgv
2012-10-08 16:47 Pawel Note Added: 0021681
2012-10-08 17:41 kgv Note Added: 0021682
2012-10-08 17:42 kgv Note Edited: 0021682 View Revisions
2012-10-08 18:37 Pawel Note Added: 0021688
2012-10-10 17:41 abv Status assigned => resolved
2012-10-10 17:44 abv Assigned To kgv => bugmaster
2012-10-10 17:44 abv Status resolved => reviewed
2012-10-10 17:53 abv Note Added: 0021711
2012-10-10 18:08 mkv Assigned To bugmaster => mkv
2012-10-16 10:16 mkv Note Added: 0021778
2012-10-16 10:16 mkv Test case number => Not needed
2012-10-16 10:16 mkv Assigned To mkv => bugmaster
2012-10-16 10:16 mkv Status reviewed => tested
2012-10-16 15:21 kgv Changeset attached => occt master dd8a4ce9
2012-10-16 15:21 kgv Assigned To bugmaster => kgv
2012-10-16 15:21 kgv Status tested => verified
2012-10-16 15:21 kgv Resolution open => fixed
2012-11-12 11:53 kgv Relationship added related to 0023500
2012-11-12 12:58 kgv Relationship added related to 0023226
2012-11-16 13:13 bugmaster Fixed in Version => 6.5.4
2012-11-16 13:18 bugmaster Status verified => closed


Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker