From 9c4f41f15fe476b34c3346ff7cf8938a6fc66835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20M=C3=A4=C3=A4tt=C3=A4?= Date: Mon, 1 Jul 2024 10:25:00 +0300 Subject: Fix setting sourcepath with dynamic string handle The dynamic string handle reference count needs to be incremented when it is set to another property to avoid deleting the string while it is being used. Task-number: QT3DS-4243 Change-Id: Ia3dce428a0c262e587581c7d231dc170ca4e3586 Reviewed-by: Janne Koskinen --- src/engine/Qt3DSRenderRuntimeBindingImplTranslation.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/engine/Qt3DSRenderRuntimeBindingImplTranslation.cpp') diff --git a/src/engine/Qt3DSRenderRuntimeBindingImplTranslation.cpp b/src/engine/Qt3DSRenderRuntimeBindingImplTranslation.cpp index 7c1700d..6fcb6bc 100644 --- a/src/engine/Qt3DSRenderRuntimeBindingImplTranslation.cpp +++ b/src/engine/Qt3DSRenderRuntimeBindingImplTranslation.cpp @@ -410,9 +410,20 @@ struct SRuntimePropertyParser CRegisteredString theTemp; ParseProperty(theTemp); CRegisteredString theNewStr = theTemp; + if (outValue.c_str() != theNewStr.c_str()) { + auto &strTable = m_RenderContext.GetStringTable(); SetDirty(); - outValue = theNewStr; + auto handle = strTable.findDynamicHandle(outValue.c_str()); + auto newHandle = strTable.findDynamicHandle(theNewStr.c_str()); + // If the new string is dynamic string, increment the ref count. + // Otherwise use the statically registered string directly. + if (newHandle) + outValue = strTable.HandleToStr(strTable.getDynamicHandle(theNewStr.c_str())); + else + outValue = theNewStr; + // Release ref count from the old string, can call even if the handle is 0. + strTable.releaseDynamicHandle(handle); return true; } return false; -- cgit v1.2.3