FreeCAD Qt5 plan for deprecated WebKit?

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
wmayer
Site Admin
Posts: 11227
Joined: Thu Feb 19, 2009 10:32 am

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby wmayer » Thu Mar 09, 2017 11:41 pm

It looks like it has something to do with AA. When I switch it off everything works as expected.

Exactly. This is what I found: http://stackoverflow.com/questions/7654 ... tisampling

With the old QGLWidget class this wasn't a problem even if AA is on. And the implementation of QGLWidget::grabFrameBuffer even directly called glReadPixels
blacey
Posts: 337
Joined: Tue Dec 08, 2015 11:28 pm

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby blacey » Fri Mar 10, 2017 7:05 am

I enabled Anti-aliasing on macOS and I still do not experience any sort of flicker during resize. While exploring the undock exception a bit more, I found this enum QSurfaceFormat::SwapBehavior that states under QSurfaceFormat::SingleBuffer that it can result in flickering. I realize that we seem to be using QSurfaceFormat::DoubleBuffer but perhaps this will serve as a hint and also shine light on the undock access violation exception (could also be a red herring)?

In terms of the access violation exception, I compiled the code with what is referred to as Zombie objects on macOS that configures the runtime to keep/track deallocated objects around long enough after deallocation to warn you if you try to access a deallocated object (i.e. invoke a method or access a property). Unfortunately, this simply allowed the undock view to run normally on macOS - I was able to select surfaces, rotate, resize, etc. So it didn't bear any fruit in the limited time I looked at it but it smells of a dellocation issue that may be affected by compiler optimization settings or perhaps the OpenGL buffering issue above. Other times, I either saw a blue-screen inside the undocked view or an partially-rendered view of the solid - by partial, I mean everything except some of the finer details almost like it raised the exception before it was able to complete rendering.

Here are some of the details as to what lldb thinks triggered the access violation:

Screen Shot 2017-03-09 at 11.02.09 PM.jpg
Screen Shot 2017-03-09 at 11.02.09 PM.jpg (513.23 KiB) Viewed 300 times

Screen Shot 2017-03-09 at 10.50.50 PM.png
Screen Shot 2017-03-09 at 10.50.50 PM.png (732.56 KiB) Viewed 300 times

I'll try to look at this some more tomorrow but I'm hoping that either @wmayer or @f3nix can spy the root cause immediately given their intimate familiarity with the FreeCAD code base and associated frameworks (Coin, OpenInventor, etc.)
Last edited by blacey on Fri Mar 10, 2017 7:35 am, edited 1 time in total.
wmayer
Site Admin
Posts: 11227
Joined: Thu Feb 19, 2009 10:32 am

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby wmayer » Fri Mar 10, 2017 9:57 am

I don't think that it's related to our custom Inventor nodes because with the old GL classes we don't get these segfaults. For testing purposes of the off-screen rendering and other stuff I am using this model here: https://forum.freecadweb.org/viewtopic. ... ncy#p67858

And to exclude any issues with our custom Inventor nodes I created an .iv file with only original Inventor classes.
Attachments
Guillotine Assembly_v21.zip
(106.01 KiB) Downloaded 2 times
wmayer
Site Admin
Posts: 11227
Joined: Thu Feb 19, 2009 10:32 am

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby wmayer » Sun Mar 12, 2017 6:22 pm

Update about the latest changes.

Things that are fixed now:
  • Box zoom/selection and cutting works properly now.
  • Print preview, creating PDF or the snapshot function works properly now (this was an issue with current context)
  • The new framebufferobject reaches now the same quality as pixel buffer in Qt 4

Open issues are still:
  • The flicker on resizing. For me this only happens if anti-aliasing is activated.
  • I don't get these error messages any more: Coin error in SoNode::GLRenderS(): GL error: 'GL_INVALID_OPERATION', nodetype: Separator (set envvar COIN_GLERROR_DEBUGGING=1 and re-run to get more information)
    But now it's: Coin warning in SoGLRenderAction::beginTraversal(): GL error before initialization: GL_INVALID_OPERATION
  • The lines of flags don't get updated when moving flags
  • The undock/dock still gives problems. In debug mode I get these errors: Coin error in SoNode::GLRenderS(): GL error: 'GL_OUT_OF_MEMORY', nodetype: Separator
wmayer
Site Admin
Posts: 11227
Joined: Thu Feb 19, 2009 10:32 am

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby wmayer » Tue Mar 14, 2017 3:20 pm

Thanks to the use of the QOpenGLDebugLogger class I was able to locate the parts that caused crashes or OpenGL errors. So, far I got no crashes any more and all the error messages reported by Coin3d are gone, too. One of the reasons was the use of glDrawBuffer. It's commented out now and I haven't noticed any regressions compared to as it was before.

However, I still have a couple of problems:
  • When I undock a window then the rendering looks weird. Sometimes it completely disappears or the shading is off. However, objects added while a window is undocked are rendered correctly.
  • When a window has enabled multisampling then this is switched off when undocking it. I haven't found a way to reactivate it.
  • When re-docking a window the canvas is at the wrong position. Only after resizing from the bottom or left side resets it.
  • The flicker on resize only happens when multisampling is on
  • The flag lines are not updated when moving the flags

EDIT: Inside the implementation of QOpenGLWidgetPrivate::initialize() the samples is explicitly set to zero which switches off anti-aliasing. When I run this in the debugger and set the value manually to e.g. 8 then the rendering later works as expected.

Edit2: The flickering only happens when the GL widget is set as viewport of the graphics view and multisampling is on. When it's used as normal widget then there is no flickering (independent of the multisampling value) and I guess it's due to how the update mechanism is implemented.
wmayer
Site Admin
Posts: 11227
Joined: Thu Feb 19, 2009 10:32 am

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby wmayer » Wed Mar 15, 2017 4:42 pm

Now I implemented a fix to draw the flag lines when needed and I found a workaround to avoid the flickering: the QOpenGLWidget class has the signal resized and when this is connected with a call of update() the 3d canvas is always repainted as soon as possible.

The only open issues now are when undocking/docking the 3d viewer:
  • When the content looks weird then some OpenGL states are messed up (like disabled GL_LIGHTING). But I don't know how this happens.
  • When the canvas is on the wrong position after re-docking then this happens when moving/resizing the 3d viewer when it's undocked. I haven't found the root cause nor do I know how to fix it. At least when manually resizing it after it's re-docked then it heals the issue.
  • The loss of multisampling after undocking. When setting a new viewport widget with the original surface format would solve this issue but when closing the application it crashes.

The open issue are no show stoppers so that the branch can be merged into master now.
ian.rees
Posts: 524
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby ian.rees » Wed Mar 15, 2017 4:45 pm

Awesome! Thanks for all your work on this - I've been using your branch on MacOS and not noticed any bugs other than the ones you knew about already. -Ian-
wmayer
Site Admin
Posts: 11227
Joined: Thu Feb 19, 2009 10:32 am

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby wmayer » Tue Mar 21, 2017 12:36 pm

When the canvas is on the wrong position after re-docking then this happens when moving/resizing the 3d viewer when it's undocked. I haven't found the root cause nor do I know how to fix it. At least when manually resizing it after it's re-docked then it heals the issue.

This was quite a nasty bug and after spending many hours on debugging I found out that the layout of the QMdiSubWindow that holds the View3DInventoris broken. Exposing the layout's invalidate() function tmp. fixed it but as soon the mdi window has been resized the issue reappeared. After spending some more hours I found out that when un-docking a child window to become a top-level window it internally creates an instance of QWindow. This QWindow then has an impact on the mdi window after re-docking it and isn't automatically destroyed. So, the fix is simple: git commit b9934f05

Now the only open issues so far are:
  • When the content looks weird then some OpenGL states are messed up (like disabled GL_LIGHTING)
  • The loss of multisampling after undocking
Jee-Bee
Posts: 614
Joined: Tue Jun 16, 2015 10:32 am
Location: Netherlands

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby Jee-Bee » Tue Mar 21, 2017 3:27 pm

wmayer wrote:I found out that when un-docking a child window to become a top-level window it internally creates an instance of QWindow. This QWindow then has an impact on the mdi window after re-docking it and isn't automatically destroyed. So, the fix is simple:...

Sounds like it's not :shock:
wmayer
Site Admin
Posts: 11227
Joined: Thu Feb 19, 2009 10:32 am

Re: FreeCAD Qt5 plan for deprecated WebKit?

Postby wmayer » Tue Mar 21, 2017 5:00 pm

Sounds like it's not

The fix itself is simple but the way to it was hard.