# HG changeset patch # User Sebastien Jodogne # Date 1720014492 -7200 # Node ID dff82fbd0a154079850d544e59d00b6b5de95b11 # Parent b124c74e696857c6989528764e54a4249515f5d3 added PythonThreadsAllower in some custom functions diff -r b124c74e6968 -r dff82fbd0a15 Sources/Plugin.cpp --- a/Sources/Plugin.cpp Wed Jul 03 15:33:21 2024 +0200 +++ b/Sources/Plugin.cpp Wed Jul 03 15:48:12 2024 +0200 @@ -35,8 +35,9 @@ #include "StorageArea.h" #include "StorageCommitmentScpCallback.h" +#include "PythonModule.h" +#include "PythonThreadsAllower.h" #include "RestCallbacks.h" -#include "PythonModule.h" #include "Autogenerated/sdk.h" @@ -71,8 +72,13 @@ else { OrthancPluginDictionaryEntry entry; + OrthancPluginErrorCode code; + + { + PythonThreadsAllower allower; + code = OrthancPluginLookupDictionary(OrthancPlugins::GetGlobalContext(), &entry, name); + } - OrthancPluginErrorCode code = OrthancPluginLookupDictionary(OrthancPlugins::GetGlobalContext(), &entry, name); if (code == OrthancPluginErrorCode_Success) { /** @@ -134,8 +140,14 @@ { OrthancPluginDicomInstance* instance = reinterpret_cast(self)->object_; - const void* data = OrthancPluginGetInstanceData(OrthancPlugins::GetGlobalContext(), instance); - size_t size = OrthancPluginGetInstanceSize(OrthancPlugins::GetGlobalContext(), instance); + const void* data; + size_t size; + + { + PythonThreadsAllower allower; + data = OrthancPluginGetInstanceData(OrthancPlugins::GetGlobalContext(), instance); + size = OrthancPluginGetInstanceSize(OrthancPlugins::GetGlobalContext(), instance); + } if (data == NULL && size != 0) @@ -170,9 +182,15 @@ { OrthancPluginImage* image = reinterpret_cast(self)->object_; - const void* buffer = OrthancPluginGetImageBuffer(OrthancPlugins::GetGlobalContext(), image); - size_t size = (OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image) * - OrthancPluginGetImageHeight(OrthancPlugins::GetGlobalContext(), image)); + const void* buffer; + size_t size; + + { + PythonThreadsAllower allower; + buffer = OrthancPluginGetImageBuffer(OrthancPlugins::GetGlobalContext(), image); + size = (OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image) * + OrthancPluginGetImageHeight(OrthancPlugins::GetGlobalContext(), image)); + } if (buffer == NULL && size != 0) @@ -215,8 +233,19 @@ } else { - OrthancPluginImage* image = OrthancPluginCreateImage( - OrthancPlugins::GetGlobalContext(), static_cast(format), width, height); + OrthancPluginImage* image; + unsigned long targetPitch = 0; + + { + PythonThreadsAllower allower; + image = OrthancPluginCreateImage( + OrthancPlugins::GetGlobalContext(), static_cast(format), width, height); + + if (image != NULL) + { + targetPitch = OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image); + } + } if (image == NULL) { @@ -228,8 +257,6 @@ else { // Copy the image line by line - unsigned long targetPitch = OrthancPluginGetImagePitch(OrthancPlugins::GetGlobalContext(), image); - const uint8_t* sourcePixels = reinterpret_cast(buffer.buf); uint8_t* targetPixels = reinterpret_cast(OrthancPluginGetImageBuffer(OrthancPlugins::GetGlobalContext(), image));