Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallelised SceneNode child bound computations. #4

Closed
wants to merge 1 commit into from

Conversation

johnhaddon
Copy link
Owner

No description provided.

@johnhaddon
Copy link
Owner Author

Yo, @andrewkaufman, would you like to comment on my half-assed branch?

@andrewkaufman
Copy link

Nah, its got conflicts. I ain't reviewing no conflicts.

@johnhaddon
Copy link
Owner Author

So, now you were mentioned earlier, do you receive additional comments that don't mention you?

@andrewkaufman
Copy link

I still got it 🎉

@johnhaddon
Copy link
Owner Author

Awesome. Let's give this a bash next time we need a bit of pre-PR discussion then...

@johnhaddon johnhaddon closed this Jul 28, 2017
johnhaddon added a commit that referenced this pull request Feb 22, 2018
Also go to great pains to document that Gaffer's computations are not restricted to a single global time, and that this plug is for the user, not the coder.

Fixes #4.
johnhaddon added a commit that referenced this pull request Mar 14, 2018
Also go to great pains to document that Gaffer's computations are not restricted to a single global time, and that this plug is for the user, not the coder.

Fixes #4.
johnhaddon added a commit that referenced this pull request Dec 19, 2019
This obviously isn't quite right, because the InteractiveRender tests crash with the following stack trace :

```
#0  0x0000000000000000 in ?? ()
#1  0x00007fffe18153a6 in foundation::auto_release_ptr<renderer::ITileCallback>::reset (this=0x7fff8c012148, ptr=0x0)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/foundation/utility/autoreleaseptr.h:187
#2  0x00007fffe181137f in renderer::(anonymous namespace)::ProgressiveFrameRenderer::~ProgressiveFrameRenderer (this=0x7fff8c0120a0, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/kernel/rendering/progressive/progressiveframerenderer.cpp:178
#3  0x00007fffe1811592 in renderer::(anonymous namespace)::ProgressiveFrameRenderer::~ProgressiveFrameRenderer (this=0x7fff8c0120a0, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/kernel/rendering/progressive/progressiveframerenderer.cpp:187
#4  0x00007fffe18115ca in renderer::(anonymous namespace)::ProgressiveFrameRenderer::release (this=0x7fff8c0120a0)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/kernel/rendering/progressive/progressiveframerenderer.cpp:191
#5  0x00007fffe1712fb7 in foundation::auto_release_ptr<renderer::IFrameRenderer>::~auto_release_ptr (this=0x7fff8c01f928, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/foundation/utility/autoreleaseptr.h:124
#6  0x00007fffe17121be in renderer::RendererComponents::~RendererComponents (this=0x7fff8c01f890, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/kernel/rendering/renderercomponents.h:73
#7  0x00007fffe1712288 in std::default_delete<renderer::RendererComponents>::operator() (this=0x7fff8c000ae0, __ptr=0x7fff8c01f890)
   at /opt/rh/devtoolset-6/root/usr/include/c++/6.3.1/bits/unique_ptr.h:76
#8  0x00007fffe1711e0d in std::unique_ptr<renderer::RendererComponents, std::default_delete<renderer::RendererComponents> >::reset (this=0x7fff8c000ae0,
   __p=0x7fff8c01f890) at /opt/rh/devtoolset-6/root/usr/include/c++/6.3.1/bits/unique_ptr.h:347
#9  0x00007fffe1710632 in renderer::CPURenderDevice::~CPURenderDevice (this=0x7fff8c0009b0, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/device/cpu/cpurenderdevice.cpp:112
#10 0x00007fffe1710988 in renderer::CPURenderDevice::~CPURenderDevice (this=0x7fff8c0009b0, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/device/cpu/cpurenderdevice.cpp:129
#11 0x00007fffe181f21c in std::default_delete<renderer::IRenderDevice>::operator() (this=0x3093868, __ptr=0x7fff8c0009b0)
   at /opt/rh/devtoolset-6/root/usr/include/c++/6.3.1/bits/unique_ptr.h:76
#12 0x00007fffe181eafd in std::unique_ptr<renderer::IRenderDevice, std::default_delete<renderer::IRenderDevice> >::~unique_ptr (this=0x3093868,
   __in_chrg=<optimized out>) at /opt/rh/devtoolset-6/root/usr/include/c++/6.3.1/bits/unique_ptr.h:239
#13 0x00007fffe181d545 in renderer::MasterRenderer::Impl::~Impl (this=0x3093820, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/kernel/rendering/masterrenderer.cpp:168
#14 0x00007fffe181cfdb in renderer::MasterRenderer::~MasterRenderer (this=0x3088d70, __in_chrg=<optimized out>)
   at /disk1/john/dev/gafferDependencies/Appleseed/working/appleseed-2.1.0-beta/src/appleseed/renderer/kernel/rendering/masterrenderer.cpp:584
#15 0x00007fffc67d0ae0 in (anonymous namespace)::AppleseedRenderer::~AppleseedRenderer() () from /disk1/john/dev/build/gaffer/lib/libGafferAppleseed.so
#16 0x00007fffd8a734b6 in GafferScene::InteractiveRender::stop() () from /disk1/john/dev/build/gaffer/lib/libGafferScene.so
#17 0x00007fffd8a735bf in GafferScene::InteractiveRender::update() () from /disk1/john/dev/build/gaffer/lib/libGafferScene.so
```
@johnhaddon johnhaddon deleted the parallelUnionOfChildBoundsRebased branch June 17, 2020 07:35
johnhaddon added a commit that referenced this pull request Oct 8, 2020
This problem could be triggered as follows :

	1. `gaffer op sequenceLs -gui`
	2. Set `dir` to a directory that doesn't exist.
	3. Hit OK to execute the Op.

It yielded an assertion failure as follows :

	```ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 0x0x7fff90001050. Receiver '' (of type 'QThread') was created in thread 0x0xa902b0", file kernel/qcoreapplication.cpp, line 578```

And a stack trace like so :

	```
	#2  0x00007fffe229d615 in qt_message_fatal (context=..., message=...) at global/qlogging.cpp:1907
	#3  0x00007fffe229e122 in QMessageLogger::fatal (this=this@entry=0x7fffa77fcd90, msg=msg@entry=0x7fffe25b0c60 "ASSERT failure in %s: \"%s\", file %s, line %d") at global/qlogging.cpp:888
	#4  0x00007fffe22985dc in qt_assert_x (where=where@entry=0x7fffe25c0144 "QCoreApplication::sendEvent", what=<optimized out>, file=file@entry=0x7fffe25c00cf "kernel/qcoreapplication.cpp", line=line@entry=578)
	    at global/qglobal.cpp:3220
	#5  0x00007fffe247aaa2 in QCoreApplicationPrivate::checkReceiverThread (receiver=receiver@entry=0xa902b0) at kernel/qcoreapplication.cpp:572
	#6  0x00007fffe16052b2 in QApplication::notify (this=0x1dc4170, receiver=0xa902b0, e=0x7fffa77fd120) at kernel/qapplication.cpp:2902
	#7  0x00007fffdc443cf6 in QApplicationWrapper::notify(QObject*, QEvent*) () from /disk1/john/dev/build/gafferPython2/lib/python2.7/site-packages/PySide2/QtWidgets.so
	#8  0x00007fffe247b0ec in QCoreApplication::notifyInternal2 (receiver=0xa902b0, event=0x7fffa77fd120) at kernel/qcoreapplication.cpp:1088
	#9  0x00007fffe247b2ea in QCoreApplication::sendEvent (receiver=receiver@entry=0xa902b0, event=event@entry=0x7fffa77fd120) at kernel/qcoreapplication.cpp:1476
	#10 0x00007fffe24b426b in QObject::setProperty (this=0xa902b0, name=0x7fffdce01d50 <PySide::invalidatePropertyName> "_PySideInvalidatePtr", value=...) at kernel/qobject.cpp:3945
	#11 0x00007fffdcdffa42 in PySide::getWrapperForQObject(QObject*, SbkObjectType*) () from /disk1/john/dev/build/gafferPython2/lib/python2.7/site-packages/PySide2/libpyside2-python2.7.so.5.12
	#12 0x00007fffdb768443 in Sbk_QObjectFunc_thread () from /disk1/john/dev/build/gafferPython2/lib/python2.7/site-packages/PySide2/QtCore.so
	```

The problem is that when PySide first makes a wrapper for a QObject, it adds a property to that object. Adding a property can only be performed on the thread that owns the object, so the first access to `__qtApplication.thread()` must be performed on the main thread. We ensure that this is the case by accessing it immediately after constructing the QApplication.

The test case for this has to be run externally via `gaffer python` because when running the full test suite we hit a code path that happens to first access `__qtApplication.thread()` from the main thread. The external script mimics what happens in `gaffer op -gui`, where we end up first accessing `__qtApplication.thread()` from a background thread.
johnhaddon added a commit that referenced this pull request Feb 20, 2024
This could be reproduced in Gaffer as follows :

1. Create an Arnold spotlight.
2. Connect a ShaderAssignment below it.
3. Focus the ShaderAssignment.
4. Enable the LightTool.
5. Delete the ShaderAssignment.

The stacktrace looked like this :

<details>

```
#0  0x00007fff7e2dba50 in GafferSceneUI::Private::Inspector::Result::value() const () from /home/john/dev/build/gaffer-1.4/lib/libGafferSceneUI.so
#1  0x00007fff7e308a3c in float const GafferSceneUI::Private::Inspector::Result::typedValue<float>(float const&) const () from /home/john/dev/build/gaffer-1.4/lib/libGafferSceneUI.so
#2  0x00007fff7e2f4ec7 in (anonymous namespace)::SpotLightHandle::handleAngles() const () from /home/john/dev/build/gaffer-1.4/lib/libGafferSceneUI.so
#3  0x00007fff7e2fe8d2 in (anonymous namespace)::SpotLightHandle::addHandleVisualisation(IECoreGL::Group*, bool, bool) const () from /home/john/dev/build/gaffer-1.4/lib/libGafferSceneUI.so
#4  0x00007fff7e2fcacd in (anonymous namespace)::LightToolHandle::renderHandle(GafferUI::Style const*, GafferUI::Style::State) const () from /home/john/dev/build/gaffer-1.4/lib/libGafferSceneUI.so
#5  0x00007fffe2b8d7c3 in GafferUI::Handle::renderLayer(GafferUI::Gadget::Layer, GafferUI::Style const*, GafferUI::Gadget::RenderReason) const () from /home/john/dev/build/gaffer-1.4/lib/libGafferUI.so
#6  0x00007fffe2c0e790 in GafferUI::ViewportGadget::renderLayerInternal(GafferUI::Gadget::RenderReason, GafferUI::Gadget::Layer, Imath_3_1::Matrix44<float> const&, Imath_3_1::Box<Imath_3_1::Vec3<float> > const&, IECoreGL::Selector*) const () from /home/john/dev/build/gaffer-1.4/lib/libGafferUI.so
#7  0x00007fffe2c1543c in GafferUI::ViewportGadget::renderInternal(GafferUI::Gadget::RenderReason, GafferUI::Gadget::Layer) const () from /home/john/dev/build/gaffer-1.4/lib/libGafferUI.so
#8  0x00007fffe2c16728 in GafferUI::ViewportGadget::render() const () from /home/john/dev/build/gaffer-1.4/lib/libGafferUI.so
```

</details>

The main cause was that `LightTool::updateHandleInspections()` was skipping the updates when there was no input scene, which meant the handles were left in a visible state when they should have been hidden. This in turn led to them querying inspectors that returned `null` results unexpectedly on the next render, because they were still connected to the now-deleted scene. This is fixed by removing the early out in `updateHandleInspections()` so that we update the inspectors (in this case, clearing them).

But we can also go further. There is no need to pass a separate scene and context to `LightToolHandle::updateHandlePath()`, because those are both accessible already via the `SceneView` it was passed on construction. So we tidy that up so we always get them from the SceneView, make the `scene()` and `handlePath()` accessors protected as per the existing todo, and remove the `context()` accessor because it is barely used.

The general principle here is that it's easier if UI components don't worry about whether or not something is connected to the ScenePlug or ImagePlugs inputs. There's no real difference between the empty scene from an unconnected input or the empty scene from a connected input that happens to output an empty scene. We're not yet consistent about this everywhere, but that's the direction we're moving in.

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Tue Feb 20 11:59:56 2024 +0000
#
# On branch lightToolCrashFix
# Changes to be committed:
#	modified:   python/GafferSceneUITest/LightToolTest.py
#	modified:   src/GafferSceneUI/LightTool.cpp
#
# Changes not staged for commit:
#	modified:   Changes.md
#
# Untracked files:
#	bits/
#	t.py
#

# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date:      Tue Feb 20 11:59:56 2024 +0000
#
# On branch lightToolCrashFix
# Changes to be committed:
#	modified:   Changes.md
#	modified:   python/GafferSceneUITest/LightToolTest.py
#	modified:   src/GafferSceneUI/LightTool.cpp
#
# Untracked files:
#	bits/
#	t.py
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants