diff --git a/Components/Bites/include/OgreBites.i b/Components/Bites/include/OgreBites.i index 5a40d3dd0a6..05abd20f0f7 100644 --- a/Components/Bites/include/OgreBites.i +++ b/Components/Bites/include/OgreBites.i @@ -1,4 +1,4 @@ -%module(package="Ogre", directors="1") Bites +%module(package="Ogre", directors="1", threads="1") Bites %{ /* Includes the header in the wrapper code */ #include "Ogre.h" @@ -15,6 +15,7 @@ #include "OgreImGuiInputListener.h" %} +%feature("nothreadallow"); %include std_vector.i %include std_string.i %include exception.i @@ -73,4 +74,4 @@ JNIEnv* OgreJNIGetEnv(); #ifndef SWIGCSHARP %include "OgreTrays.h" %include "OgreAdvancedRenderControls.h" -#endif \ No newline at end of file +#endif diff --git a/Docs/src/tutorials/numpy.md b/Docs/src/tutorials/numpy.md index fda97c5431a..a526e52e78c 100644 --- a/Docs/src/tutorials/numpy.md +++ b/Docs/src/tutorials/numpy.md @@ -59,6 +59,3 @@ def printer(): threading.Thread(target=printer).start() root.startRendering() ``` - -The "printer" Thread will be blocked until the rendering is finished. -To allow background threads to run, you can use `root.allowPyThread()`, which will release the GIL during swapping, while rendering is waiting for vsync. \ No newline at end of file diff --git a/OgreMain/include/Ogre.i b/OgreMain/include/Ogre.i index d7850673f65..d6e9b7370ca 100644 --- a/OgreMain/include/Ogre.i +++ b/OgreMain/include/Ogre.i @@ -1,4 +1,4 @@ - %module(package="Ogre", directors="1") Ogre + %module(package="Ogre", directors="1", threads="1") Ogre %{ /* Includes the header in the wrapper code */ #include "Ogre.h" @@ -19,6 +19,7 @@ #include "OgreDefaultDebugDrawer.h" %} +%feature("nothreadallow"); %include stdint.i %include std_shared_ptr.i %include std_string.i @@ -515,6 +516,7 @@ SHARED_PTR(FileHandleDataStream); %include "OgreCodec.h" %include "OgreSerializer.h" %include "OgreScriptLoader.h" + // Listeners %feature("director") Ogre::FrameListener; %include "OgreFrameListener.h" @@ -528,6 +530,7 @@ SHARED_PTR(FileHandleDataStream); %include "OgreRenderTargetListener.h" %feature("director") Ogre::MeshSerializerListener; %feature("director") Ogre::ResourceLoadingListener; + // More Data Types %ignore Ogre::ColourValue::getHSB; // deprecated %include "OgreColourValue.h" @@ -925,33 +928,10 @@ SHARED_PTR(Mesh); %ignore Ogre::Root::createSceneManager(uint16, const String&); %ignore Ogre::Root::getMovableObjectFactoryIterator; #ifdef SWIGPYTHON -%{ -class ThreadAllowFrameListener : public Ogre::FrameListener { - PyThreadState* _save = 0; -public: - bool frameRenderingQueued(const Ogre::FrameEvent& evt) - { - if(!_save) - _save = PyEval_SaveThread(); - return true; - } - bool frameEnded(const Ogre::FrameEvent& evt) - { - if(_save) { - PyEval_RestoreThread(_save); - _save = 0; - } - return true; - } -}; -%} -%extend Ogre::Root { - void allowPyThread() - { - static ThreadAllowFrameListener listener; - $self->addFrameListener(&listener); - } -} +/* Unlocks SIG when called from python */ +%threadallow Ogre::Root::startRendering; +%threadallow Ogre::Root::renderOneFrame; +%threadallow Ogre::Root::_updateAllRenderTargets; #endif %include "OgreRoot.h" // dont wrap: not useful in high level languages