gkv311 / occt-samples-qopenglwidget

Open CASCADE Technology sample - 3D Viewer within Qt Widgets window
Other
55 stars 16 forks source link

Crash: Two separate views, shared context #12

Open rainman110 opened 1 year ago

rainman110 commented 1 year ago

I successfully used your example two create two separate views. it works out of the box.

Next, I tried to extract the V3d_Viewer and AIS_InteractiveContext out of the widget to create a shared state between both views (i.e. have the same context with different views).

In this case, the application crashes at the end of the second call to initializeGL, concretely at the line myView->SetWindow.

This worked well with the "normal" occt qt examples, but does not work anymore with your QOpenGlWidget-based example.

Do you have any suggestions, how I could use multiple views of the same context?

gkv311 commented 1 year ago

If you would share a sample project it would be simpler to understand what you are trying to do / reproduce the problem

rainman110 commented 1 year ago

Sure, I'll provide the very quick and dirty example - based on yours - in a fork.

rainman110 commented 1 year ago

@gkv311 Here's the example on my fork in the branch "dual_view" https://github.com/rainman110/occt-samples-qopenglwidget/tree/dual_view

I extracted the viewer and the context into a separate objects "scene", which should hold the shared state.

rainman110 commented 1 year ago

@gkv311 Did you have any chance to look at the example. I am a bit puzzled, what could be happening.

Conceptually, what is required to have to separate viewers from the same scene?

gkv311 commented 1 year ago

@gkv311 Did you have any chance to look at the example. I am a bit puzzled, what could be happening.

Sorry, need to find some time to setup Linux + OCCT + sample environment. It might be tricky from OCCT side wrapping two existing OpenGL views sharing common context, though conceptually it should work.

Meanwhile I've pushed another option for splitting views using Subview API introduced by OCCT 7.7. Tested on Windows platform for now.

image

rainman110 commented 1 year ago

Awesome! I'll gonna try this latest tomorrow.

Strangely, I always successfully used a multi view application based on the old qt example, that is part of the occt examples.

Thank you for looking into it!

gkv311 commented 1 year ago

Strangely, I always successfully used a multi view application based on the old qt example, that is part of the occt examples.

You've missed the point about wrapping alien OpenGL context created by Qt (QOpenGlWidget). Old OCCT Qt samples do all OpenGL management on their own, taking from Qt only created native window handles.

rainman110 commented 1 year ago

Oh yes. You're right. With the new approach, there are two separate OpenGL contexts created by each of the qopenglwidgets. I am looking forward to look into your changed code.