From 5788d00c3599e1db99323c79802999acf3d29921 Mon Sep 17 00:00:00 2001 From: AdventureT Date: Sat, 6 Jan 2024 11:20:52 +0100 Subject: [PATCH] Fix TWString bug --- OpenJPOG/Source/Tasks/ARootTask.cpp | 2 +- Toshi/Include/TKernel/TWString.h | 3 ++- Toshi/Include/TRenderD3D/TRenderD3DInterface.h | 3 +++ Toshi/Source/TKernel/TWString.cpp | 7 +++---- Toshi/Source/TRender/TNullResource.cpp | 2 +- Toshi/Source/TRender/TRenderInterface.cpp | 9 ++------- Toshi/Source/TRenderD3D/TD3DVertexPoolResource.cpp | 1 + Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp | 2 ++ 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/OpenJPOG/Source/Tasks/ARootTask.cpp b/OpenJPOG/Source/Tasks/ARootTask.cpp index dfb8dc7..1cc8331 100644 --- a/OpenJPOG/Source/Tasks/ARootTask.cpp +++ b/OpenJPOG/Source/Tasks/ARootTask.cpp @@ -30,7 +30,7 @@ void ARootTask::UnloadFrontEndController() void ARootTask::AllocateRenderInterface() { g_oTheApp.GetKernel()->LoadInterface("TRenderD3DInterface"); - m_pRenderInterface = (TRenderInterface*)TFindClass("TRenderD3DInterface", TNULL)->CreateObject(); + m_pRenderInterface = (TRenderInterface*)TFindClass(TRenderD3DInterface, TNULL)->CreateObject(); m_pRenderInterface->Create(g_oTheApp.GetKernel()); m_pRenderInterface->DumpStats(); } diff --git a/Toshi/Include/TKernel/TWString.h b/Toshi/Include/TKernel/TWString.h index ba9280b..5d20382 100644 --- a/Toshi/Include/TKernel/TWString.h +++ b/Toshi/Include/TKernel/TWString.h @@ -4,6 +4,7 @@ #include #include "TDebug.h" #include "TSystemTools.h" +#include TOSHI_NAMESPACE_BEGIN @@ -140,7 +141,7 @@ class TKERNELINTERFACE_EXPORTS TWString void FreeBuffer() { if (m_iStrLen != 0) { - free(m_pBuffer); + tfree(m_pBuffer); m_pBuffer = TNULL; } Reset(); diff --git a/Toshi/Include/TRenderD3D/TRenderD3DInterface.h b/Toshi/Include/TRenderD3D/TRenderD3DInterface.h index 1d2c3e0..b4da0a9 100644 --- a/Toshi/Include/TRenderD3D/TRenderD3DInterface.h +++ b/Toshi/Include/TRenderD3D/TRenderD3DInterface.h @@ -13,6 +13,9 @@ class TMSWindow; class TRENDERINTERFACED3D_EXPORTS TRenderD3DInterface : public TRenderInterface { + + DECLARE_DYNAMIC(TRenderD3DInterface) + public: TRenderD3DInterface(); diff --git a/Toshi/Source/TKernel/TWString.cpp b/Toshi/Source/TKernel/TWString.cpp index f1159ef..254c1fc 100644 --- a/Toshi/Source/TKernel/TWString.cpp +++ b/Toshi/Source/TKernel/TWString.cpp @@ -1,7 +1,6 @@ #include "TWString.h" #include "TSystemTools.h" #include -#include TOSHI_NAMESPACE_USING @@ -25,7 +24,7 @@ TBOOL TWString::AllocBuffer(TINT a_iLength, TBOOL a_bClear) if (newExcessLen < 0 || newExcessLen > 0xFF) { if (m_iStrLen != 0 && a_bClear) tfree(m_pBuffer); - m_pBuffer = (TPWCHAR)tmalloc((a_iLength * 2) + 1, TNULL, -1); + m_pBuffer = (TPWCHAR)tmalloc((a_iLength + 1) * 2, TNULL, -1); m_iExcessLen = 0; TASSERT(m_pBuffer != TNULL); hasChanged = TTRUE; @@ -97,7 +96,7 @@ void TWString::Copy(const TWString& a_rOther, TINT a_iLength) if (*this != a_rOther) { if (a_rOther.m_iStrLen < a_iLength || a_iLength == -1) a_iLength = a_rOther.m_iStrLen; AllocBuffer(a_iLength); - TSystem::MemCopy(m_pBuffer, a_rOther.m_pBuffer, a_iLength); + TSystem::StringCopy(m_pBuffer, a_rOther.m_pBuffer, a_iLength); m_pBuffer[a_iLength] = '\0'; } } @@ -108,7 +107,7 @@ void TWString::Copy(TPCWCHAR a_pcString, TINT a_iLength) TINT iLength = a_pcString ? TSystem::StringLength(a_pcString) : 0; if (iLength < a_iLength || a_iLength == -1) a_iLength = iLength; AllocBuffer(a_iLength, TTRUE); - TSystem::MemCopy(m_pBuffer, a_pcString, a_iLength); + TSystem::StringCopy(m_pBuffer, a_pcString, a_iLength); m_pBuffer[a_iLength] = '\0'; } } diff --git a/Toshi/Source/TRender/TNullResource.cpp b/Toshi/Source/TRender/TNullResource.cpp index 65edfc1..ef94767 100644 --- a/Toshi/Source/TRender/TNullResource.cpp +++ b/Toshi/Source/TRender/TNullResource.cpp @@ -2,4 +2,4 @@ TOSHI_NAMESPACE_USING -IMPLEMENT_DYNAMIC(TNullResource, TResource) \ No newline at end of file +IMPLEMENT_DYNCREATE(TNullResource, TResource) \ No newline at end of file diff --git a/Toshi/Source/TRender/TRenderInterface.cpp b/Toshi/Source/TRender/TRenderInterface.cpp index 610eb3b..21d22ea 100644 --- a/Toshi/Source/TRender/TRenderInterface.cpp +++ b/Toshi/Source/TRender/TRenderInterface.cpp @@ -13,7 +13,9 @@ TRenderInterface::TRenderInterface() { m_bIsCreated = TFALSE; m_pDefaultRenderContext = TNULL; + m_pCurrentRenderContext = TNULL; m_pKernel = TNULL; + m_iResourceCount = 1; TASSERT(s_Interface == TNULL); s_Interface = this; TSystem::MemSet(m_aSysResources, 0, sizeof(m_aSysResources)); @@ -29,13 +31,6 @@ TBOOL TRenderInterface::Create(TKernelInterface* pKernelInterface) return TTRUE; } -//class TVertexFactoryResource : public TVertexFactoryFormat, public TResource -//{ -// DECLARE_DYNAMIC(TVertexFactoryResource) -//}; - -//IMPLEMENT_DYNCREATE(TVertexFactoryResource, TResource) - TBOOL TRenderInterface::CreateSystemResources() { { diff --git a/Toshi/Source/TRenderD3D/TD3DVertexPoolResource.cpp b/Toshi/Source/TRenderD3D/TD3DVertexPoolResource.cpp index a424185..e25ba8d 100644 --- a/Toshi/Source/TRenderD3D/TD3DVertexPoolResource.cpp +++ b/Toshi/Source/TRenderD3D/TD3DVertexPoolResource.cpp @@ -6,6 +6,7 @@ TOSHI_NAMESPACE_USING IMPLEMENT_DYNCREATE(TVertexPoolResource, TVertexPoolResourceInterface) + TBOOL TVertexPoolResource::Validate() { if (IsValid()) { diff --git a/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp b/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp index a51c57a..2bed026 100644 --- a/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp +++ b/Toshi/Source/TRenderD3D/TRenderD3DInterface.cpp @@ -5,6 +5,8 @@ TOSHI_NAMESPACE_USING +IMPLEMENT_DYNCREATE(TRenderD3DInterface, TRenderInterface) + TRenderD3DInterface::TRenderD3DInterface() { m_pD3DInterface = NULL;