From 3c19b8c679b29dd2ee85c58e66012af71cee3a3f Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:42:41 +0100 Subject: [PATCH 01/17] Fix operators --- Engine/source/T3D/lighting/reflectionProbe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/T3D/lighting/reflectionProbe.cpp b/Engine/source/T3D/lighting/reflectionProbe.cpp index c7a9cfed8..c947413c1 100644 --- a/Engine/source/T3D/lighting/reflectionProbe.cpp +++ b/Engine/source/T3D/lighting/reflectionProbe.cpp @@ -709,7 +709,7 @@ void ReflectionProbe::processStaticCubemap() IBLUtilities::SaveCubeMap(prefilterFileName, mPrefilterMap->mCubemap); } - if ((mIrridianceMap != nullptr || !mIrridianceMap->mCubemap.isNull()) && (mPrefilterMap != nullptr || !mPrefilterMap->mCubemap.isNull())) + if ((mIrridianceMap != nullptr && !mIrridianceMap->mCubemap.isNull()) && (mPrefilterMap != nullptr && !mPrefilterMap->mCubemap.isNull())) { mProbeInfo.mPrefilterCubemap = mPrefilterMap->mCubemap; mProbeInfo.mIrradianceCubemap = mIrridianceMap->mCubemap; From 4f4184ab683e80192cc00cc5c358abca0bca5cec Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:44:52 +0100 Subject: [PATCH 02/17] Assign result from `mClampF` --- Engine/source/lighting/common/projectedShadow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/lighting/common/projectedShadow.cpp b/Engine/source/lighting/common/projectedShadow.cpp index 2860d71fb..030c37fd7 100644 --- a/Engine/source/lighting/common/projectedShadow.cpp +++ b/Engine/source/lighting/common/projectedShadow.cpp @@ -395,7 +395,7 @@ void ProjectedShadow::_calcScore( const SceneRenderState *state ) F32 secs = mFloor( (F32)msSinceLastRender / 1000.0f ); mScore = pct + secs; - mClampF( mScore, 0.0f, 2000.0f ); + mScore = mClampF( mScore, 0.0f, 2000.0f ); } void ProjectedShadow::update( const SceneRenderState *state ) From fa5b377ec39bb1fc320e8b282b5f08e2b84b6f74 Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:47:04 +0100 Subject: [PATCH 03/17] Fix argument to `dStrncat` --- Engine/source/gfx/D3D11/gfxD3D11Device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp index b1af047bb..c57c6618b 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp @@ -280,7 +280,7 @@ void GFXD3D11Device::enumerateAdapters(Vector &adapterList) SAFE_DELETE_ARRAY(str); dStrncpy(toAdd->mName, Description.c_str(), GFXAdapter::MaxAdapterNameLen); - dStrncat(toAdd->mName, " (D3D11)", GFXAdapter::MaxAdapterNameLen); + dStrncat(toAdd->mName, " (D3D11)", 8); IDXGIOutput* pOutput = NULL; HRESULT hr; From 7519f18035cfb55b46bc986ffd37f8247527ce0d Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:48:42 +0100 Subject: [PATCH 04/17] Check correct variable --- Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp b/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp index 6344faa2a..a095367f0 100644 --- a/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp +++ b/Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.cpp @@ -2704,7 +2704,7 @@ SceneObject* GuiConvexEditorCtrl::createPolyhedralObject(const char* className, // Create the object. SceneObject* object = dynamic_cast< SceneObject* >(classRep->create()); - if (!Object) + if (!object) { Con::errorf("WorldEditor::createPolyhedralObject - Could not create SceneObject with class '%s'", className); return NULL; From 518f2c6a276c98f21be025a99b392d7c494d7aaa Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:51:56 +0100 Subject: [PATCH 05/17] Release memory --- Engine/source/console/console.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Engine/source/console/console.cpp b/Engine/source/console/console.cpp index 1c96a15fb..643baa421 100644 --- a/Engine/source/console/console.cpp +++ b/Engine/source/console/console.cpp @@ -1302,7 +1302,8 @@ bool executeFile(const char* fileName, bool noCalls, bool journalScript) CodeBlock *newCodeBlock = new CodeBlock(); newCodeBlock->compileExec(scriptFileName, script, noCalls, 0); delete[] script; - + delete newCodeBlock; + execDepth--; return true; } @@ -1476,6 +1477,7 @@ bool executeFile(const char* fileName, bool noCalls, bool journalScript) code->read(scriptFileName, *compiledStream); delete compiledStream; code->exec(0, scriptFileName, NULL, 0, NULL, noCalls, NULL, 0); + delete code; ret = true; } else From acc2e73f483d0aff8e89e44d18f04553cf0b0e7f Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:53:02 +0100 Subject: [PATCH 06/17] Release memory --- Engine/source/console/telnetDebugger.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Engine/source/console/telnetDebugger.cpp b/Engine/source/console/telnetDebugger.cpp index d3b163f1f..cc810a8a1 100644 --- a/Engine/source/console/telnetDebugger.cpp +++ b/Engine/source/console/telnetDebugger.cpp @@ -925,6 +925,7 @@ void TelnetDebugger::evaluateExpression(const char *tag, S32 frame, const char * dSprintf( buffer, len, format, tag, result.getString()[0] ? result.getString() : "\"\"" ); send( buffer ); + delete newCodeBlock; delete [] buffer; } From 18ca6c406a2d6f91d550e6b33db42eeee70b5bfc Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:54:21 +0100 Subject: [PATCH 07/17] Prevent memory leak --- Engine/source/sim/netConnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/sim/netConnection.cpp b/Engine/source/sim/netConnection.cpp index 9309674a9..ac3a2c325 100644 --- a/Engine/source/sim/netConnection.cpp +++ b/Engine/source/sim/netConnection.cpp @@ -980,7 +980,7 @@ bool NetConnection::readDemoStartBlock(BitStream* stream) bool NetConnection::startDemoRecord(const char *fileName) { - FileStream *fs = new FileStream; + FileStream *fs = NULL; if((fs = FileStream::createAndOpen( fileName, Torque::FS::File::Write )) == NULL) return false; From 390be9814025100f2abbe650400a87530ad51d66 Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:55:39 +0100 Subject: [PATCH 08/17] Release memory --- Engine/source/gfx/bitmap/ddsFile.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Engine/source/gfx/bitmap/ddsFile.cpp b/Engine/source/gfx/bitmap/ddsFile.cpp index 3d9c33685..8014a8376 100644 --- a/Engine/source/gfx/bitmap/ddsFile.cpp +++ b/Engine/source/gfx/bitmap/ddsFile.cpp @@ -123,7 +123,7 @@ U32 DDSFile::getSurfaceSize( U32 height, U32 width, U32 mipLevel ) const if(mFlags.test(CompressedData)) { // From the directX docs: - // max(1, width ๗ 4) x max(1, height ๗ 4) x 8(DXT1) or 16(DXT2-5) + // max(1, width รท 4) x max(1, height รท 4) x 8(DXT1) or 16(DXT2-5) U32 sizeMultiple = 0; @@ -178,7 +178,7 @@ U32 DDSFile::getSizeInBytes( GFXFormat format, U32 height, U32 width, U32 mipLev "DDSFile::getSizeInBytes - Must be a Block Compression format!" ); // From the directX docs: - // max(1, width ๗ 4) x max(1, height ๗ 4) x 8(DXT1) or 16(DXT2-5) + // max(1, width รท 4) x max(1, height รท 4) x 8(DXT1) or 16(DXT2-5) U32 sizeMultiple = 0; if ( format == GFXFormatBC1 || format == GFXFormatBC1_SRGB || format == GFXFormatBC4) @@ -744,6 +744,7 @@ DDSFile *DDSFile::createDDSCubemapFileFromGBitmaps(GBitmap **gbmps) GFXFormat fmt = pBitmap->getFormat(); if (fmt != GFXFormatR8G8B8A8 && fmt != GFXFormatR16G16B16A16F) { + delete ret; Con::errorf("createDDSCubemapFileFromGBitmaps: unsupported format"); return NULL; } @@ -807,4 +808,4 @@ DefineEngineFunction( getActiveDDSFiles, S32, (),, "@ingroup Rendering\n" ) { return DDSFile::smActiveCopies; -} \ No newline at end of file +} From 3c0a251f714e05a241010eed7e395ecafb18e357 Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:58:16 +0100 Subject: [PATCH 09/17] Release memory --- Engine/source/gfx/bitmap/gBitmap.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Engine/source/gfx/bitmap/gBitmap.cpp b/Engine/source/gfx/bitmap/gBitmap.cpp index 281ee7a5d..355bf7486 100644 --- a/Engine/source/gfx/bitmap/gBitmap.cpp +++ b/Engine/source/gfx/bitmap/gBitmap.cpp @@ -1436,6 +1436,7 @@ DefineEngineFunction(saveScaledImage, bool, (const char* bitmapSource, const cha if (!fs.open(destinationPath.getFullPath(), Torque::FS::File::Write)) { Con::errorf("saveScaledImage() - Failed to open output file '%s'!", bitmapDest); + delete image; return false; } else @@ -1443,6 +1444,7 @@ DefineEngineFunction(saveScaledImage, bool, (const char* bitmapSource, const cha image->writeBitmap("png", fs); fs.close(); + delete image; } return true; From e46e744dc7a524ab2799039e1e4fbdff81e4a62c Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:59:17 +0100 Subject: [PATCH 10/17] Release memory --- Engine/source/shaderGen/shaderGen.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Engine/source/shaderGen/shaderGen.cpp b/Engine/source/shaderGen/shaderGen.cpp index 90ca96e65..9ae35d474 100644 --- a/Engine/source/shaderGen/shaderGen.cpp +++ b/Engine/source/shaderGen/shaderGen.cpp @@ -200,6 +200,7 @@ void ShaderGen::generateShader( const MaterialFeatureData &featureData, if(!s->open(pixShaderName, Torque::FS::File::Write )) { AssertFatal(false, "Failed to open Shader Stream" ); + delete s; return; } From 11a9edd26354d9d6944bffc0b901fcf13a9e89e2 Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:01:36 +0100 Subject: [PATCH 11/17] Release memory --- Engine/source/terrain/terrImport.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Engine/source/terrain/terrImport.cpp b/Engine/source/terrain/terrImport.cpp index 88d0c5217..98e7eae8c 100644 --- a/Engine/source/terrain/terrImport.cpp +++ b/Engine/source/terrain/terrImport.cpp @@ -60,6 +60,7 @@ DefineEngineStaticMethod( TerrainBlock, createNew, S32, (String terrainName, U32 if( !terrain->setFile( terrFileName ) ) { Con::errorf( "TerrainBlock::createNew - error creating '%s'", terrFileName.c_str() ); + delete terrain; return 0; } From 2efd5f0acd3c4b0286abaf1f95e7a7ceaae0631e Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:03:17 +0100 Subject: [PATCH 12/17] Fix potential index out of bounds --- Engine/source/console/fileSystemFunctions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/source/console/fileSystemFunctions.cpp b/Engine/source/console/fileSystemFunctions.cpp index a9e2f47e6..b6fb119ba 100644 --- a/Engine/source/console/fileSystemFunctions.cpp +++ b/Engine/source/console/fileSystemFunctions.cpp @@ -490,8 +490,8 @@ DefineEngineFunction(getDirectoryList, String, ( const char* path, S32 depth ), if (fullpath[dStrlen(fullpath) - 1] != '/') { S32 pos = dStrlen(fullpath); - fullpath[pos] = '/'; - fullpath[pos + 1] = '\0'; + fullpath[pos - 1] = '/'; + fullpath[pos] = '\0'; } // Dump the directories. From 2e1cfe93320877b1124ed206737dba6f535f0d1f Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sat, 4 Mar 2023 22:05:43 +0100 Subject: [PATCH 13/17] Fix potential index out of bounds --- Engine/source/T3D/shapeImage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/T3D/shapeImage.cpp b/Engine/source/T3D/shapeImage.cpp index f921aa680..c71c6f938 100644 --- a/Engine/source/T3D/shapeImage.cpp +++ b/Engine/source/T3D/shapeImage.cpp @@ -576,7 +576,7 @@ bool ShapeBaseImageData::preload(bool server, String &errorStr) void ShapeBaseImageData::handleStateSoundTrack(const U32& stateId) { - if (stateId > MaxStates) + if (stateId >= MaxStates) return; StateData& s = state[stateId]; From 77e808cc3a01577830ce09cb9dbc6932d6fb9cb3 Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sun, 5 Mar 2023 11:28:23 +0100 Subject: [PATCH 14/17] Use correct calculation for `dStrncat` --- Engine/source/gfx/D3D11/gfxD3D11Device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp index c57c6618b..96078b88f 100644 --- a/Engine/source/gfx/D3D11/gfxD3D11Device.cpp +++ b/Engine/source/gfx/D3D11/gfxD3D11Device.cpp @@ -280,7 +280,7 @@ void GFXD3D11Device::enumerateAdapters(Vector &adapterList) SAFE_DELETE_ARRAY(str); dStrncpy(toAdd->mName, Description.c_str(), GFXAdapter::MaxAdapterNameLen); - dStrncat(toAdd->mName, " (D3D11)", 8); + dStrncat(toAdd->mName, " (D3D11)", sizeof(toAdd->mName) - strlen(toAdd->mName) - 1); IDXGIOutput* pOutput = NULL; HRESULT hr; From 70a464b3f4e9f4f20f3ba888eb20236cb88d7499 Mon Sep 17 00:00:00 2001 From: Johan Mattsson Date: Sun, 5 Mar 2023 11:56:47 +0100 Subject: [PATCH 15/17] Fix corruption of file encoding. --- Engine/source/gfx/bitmap/ddsFile.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Engine/source/gfx/bitmap/ddsFile.cpp b/Engine/source/gfx/bitmap/ddsFile.cpp index 8014a8376..e95e6e957 100644 --- a/Engine/source/gfx/bitmap/ddsFile.cpp +++ b/Engine/source/gfx/bitmap/ddsFile.cpp @@ -123,7 +123,7 @@ U32 DDSFile::getSurfaceSize( U32 height, U32 width, U32 mipLevel ) const if(mFlags.test(CompressedData)) { // From the directX docs: - // max(1, width รท 4) x max(1, height รท 4) x 8(DXT1) or 16(DXT2-5) + // max(1, width ๗ 4) x max(1, height ๗ 4) x 8(DXT1) or 16(DXT2-5) U32 sizeMultiple = 0; @@ -178,7 +178,7 @@ U32 DDSFile::getSizeInBytes( GFXFormat format, U32 height, U32 width, U32 mipLev "DDSFile::getSizeInBytes - Must be a Block Compression format!" ); // From the directX docs: - // max(1, width รท 4) x max(1, height รท 4) x 8(DXT1) or 16(DXT2-5) + // max(1, width ๗ 4) x max(1, height ๗ 4) x 8(DXT1) or 16(DXT2-5) U32 sizeMultiple = 0; if ( format == GFXFormatBC1 || format == GFXFormatBC1_SRGB || format == GFXFormatBC4) @@ -808,4 +808,4 @@ DefineEngineFunction( getActiveDDSFiles, S32, (),, "@ingroup Rendering\n" ) { return DDSFile::smActiveCopies; -} +} \ No newline at end of file From 5b8bfffdec6984e8f232699de4cf51d0f3285b2d Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sun, 5 Mar 2023 12:12:57 +0100 Subject: [PATCH 16/17] Fix operator --- Engine/source/renderInstance/renderProbeMgr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/renderInstance/renderProbeMgr.cpp b/Engine/source/renderInstance/renderProbeMgr.cpp index 7f8a3dc96..0f1ce87f6 100644 --- a/Engine/source/renderInstance/renderProbeMgr.cpp +++ b/Engine/source/renderInstance/renderProbeMgr.cpp @@ -798,7 +798,7 @@ void RenderProbeMgr::_update4ProbeConsts(const SceneData& sgData, shaderConsts->setSafe(probeShaderConsts->mProbeConfigDataArraySC, probeConfigAlignedArray); } - if (mBRDFTexture.isValid(), probeShaderConsts->mBRDFTextureMap->getSamplerRegister() != -1) + if (mBRDFTexture.isValid() && probeShaderConsts->mBRDFTextureMap->getSamplerRegister() != -1) GFX->setTexture(probeShaderConsts->mBRDFTextureMap->getSamplerRegister(), mBRDFTexture); if (mWetnessTexture.isValid() && probeShaderConsts->mWetnessTextureMap->getSamplerRegister() != -1) From 0cbb4fc8a1bc3c912bad7d6c0055a265bec45e4c Mon Sep 17 00:00:00 2001 From: Johan Mattsson <39247600+mjunix@users.noreply.github.com> Date: Sun, 5 Mar 2023 12:14:17 +0100 Subject: [PATCH 17/17] Use bitwise instead of logical OR --- Engine/source/T3D/gameBase/gameBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/T3D/gameBase/gameBase.cpp b/Engine/source/T3D/gameBase/gameBase.cpp index 8f9b04a99..86225702f 100644 --- a/Engine/source/T3D/gameBase/gameBase.cpp +++ b/Engine/source/T3D/gameBase/gameBase.cpp @@ -456,7 +456,7 @@ F32 GameBase::getUpdatePriority(CameraScopeQuery *camInfo, U32 updateMask, S32 u // Weight by interest. F32 wInterest; - if (getTypeMask() & (PlayerObjectType || VehicleObjectType )) + if (getTypeMask() & (PlayerObjectType | VehicleObjectType )) wInterest = 0.75f; else if (getTypeMask() & ProjectileObjectType) {