From b82f8fb4e780465c482f5e52cf32ea74e11af192 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Thu, 6 Jun 2024 15:40:53 +0200 Subject: [PATCH] Error on creating Effect with byte array and range #7794 (#8323) --- MonoGame.Framework/Graphics/Effect/Effect.cs | 2 +- Tests/Framework/Graphics/EffectTest.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/MonoGame.Framework/Graphics/Effect/Effect.cs b/MonoGame.Framework/Graphics/Effect/Effect.cs index 091ada2c5a4..8b56508b0ff 100644 --- a/MonoGame.Framework/Graphics/Effect/Effect.cs +++ b/MonoGame.Framework/Graphics/Effect/Effect.cs @@ -156,7 +156,7 @@ private MGFXHeader ReadHeader(byte[] effectCode, int index) header.Version = (int)effectCode[index++]; header.Profile = (int)effectCode[index++]; header.EffectKey = BitConverter.ToInt32(effectCode, index); index += 4; - header.HeaderSize = index; + header.HeaderSize = 10; if (header.Signature != MGFXHeader.MGFXSignature) throw new Exception("This does not appear to be a MonoGame MGFX file!"); diff --git a/Tests/Framework/Graphics/EffectTest.cs b/Tests/Framework/Graphics/EffectTest.cs index c7266dae3ef..72849f25774 100644 --- a/Tests/Framework/Graphics/EffectTest.cs +++ b/Tests/Framework/Graphics/EffectTest.cs @@ -11,6 +11,17 @@ namespace MonoGame.Tests.Graphics [TestFixture] internal class EffectTest : GraphicsDeviceTestFixtureBase { + [Test] + public void EffectConstructorShouldAllowIndexAndCount() + { + byte[] mgfxo = EffectResource.BasicEffect.Bytecode; + var index = 100000; + var byteArray = new byte[index + mgfxo.Length]; + mgfxo.CopyTo(byteArray, index); + Effect effect = null; + Assert.DoesNotThrow(() => { effect = new Effect(game.GraphicsDevice, byteArray, index, mgfxo.Length); }); + effect.Dispose(); + } [Test] public void EffectPassShouldSetTexture()