From 7fcb0a1da7c50e108806ac46e993994c34dc7464 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:46:47 -0400 Subject: [PATCH 01/15] change terrain brush size with scroll --- Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs | 8 ++++++++ Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs | 4 ++-- Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs | 8 ++++++++ Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs b/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs index c16bdd7e6..dd837fe00 100644 --- a/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs +++ b/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs @@ -150,6 +150,14 @@ namespace FlaxEditor.Tools.Terrain return; } + // Increase or decrease brush size with scroll + if (Input.GetKey(KeyboardKeys.Shift)) + { + var currentBrush = Mode.CurrentBrush; + currentBrush.Size += dt * currentBrush.Size * Input.Mouse.ScrollDelta * 5f; + Mode.CurrentBrush = currentBrush; + } + // Check if no terrain is selected var terrain = SelectedTerrain; if (!terrain) diff --git a/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs index 1d1bf87ca..a68b90ce8 100644 --- a/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs +++ b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs @@ -139,9 +139,9 @@ namespace FlaxEditor.Tools.Terrain } /// - /// Gets the current brush. + /// Gets or set the current brush. /// - public Brush CurrentBrush => _brushes[(int)_brushType]; + public Brush CurrentBrush { get => _brushes[(int)_brushType]; set => _brushes[(int)_brushType] = value; } /// /// Gets the circle brush instance. diff --git a/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs b/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs index 96270a740..837c86dcb 100644 --- a/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs +++ b/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs @@ -158,6 +158,14 @@ namespace FlaxEditor.Tools.Terrain return; } + // Increase or decrease brush size with scroll + if (Input.GetKey(KeyboardKeys.Shift)) + { + var currentBrush = Mode.CurrentBrush; + currentBrush.Size += dt * currentBrush.Size * Input.Mouse.ScrollDelta * 5f; + Mode.CurrentBrush = currentBrush; + } + // Check if selected terrain was changed during painting if (terrain != _paintTerrain && IsPainting) { diff --git a/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs b/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs index 4b19cfbde..b99ac135f 100644 --- a/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs +++ b/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs @@ -158,9 +158,9 @@ namespace FlaxEditor.Tools.Terrain } /// - /// Gets the current brush. + /// Gets or set the current brush. /// - public Brush CurrentBrush => _brushes[(int)_brushType]; + public Brush CurrentBrush { get => _brushes[(int)_brushType]; set => _brushes[(int)_brushType] = value; } /// /// Gets the circle brush instance. From 3ed28998e9840c2f6d8888e1bc0b93ae9df69db6 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Thu, 21 Sep 2023 21:28:55 +0300 Subject: [PATCH 02/15] Add more descriptive deprecation messages --- .../CustomEditors/Elements/DoubleValueElement.cs | 2 +- .../CustomEditors/Elements/FloatValueElement.cs | 2 +- Source/Engine/Graphics/Mesh.cs | 12 ++++++------ Source/Engine/Graphics/SkinnedMesh.cs | 6 +++--- Source/Engine/Physics/CollisionData.cs | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Source/Editor/CustomEditors/Elements/DoubleValueElement.cs b/Source/Editor/CustomEditors/Elements/DoubleValueElement.cs index e46040a42..07af5e991 100644 --- a/Source/Editor/CustomEditors/Elements/DoubleValueElement.cs +++ b/Source/Editor/CustomEditors/Elements/DoubleValueElement.cs @@ -22,7 +22,7 @@ namespace FlaxEditor.CustomEditors.Elements /// /// [Deprecated on 26.05.2022, expires on 26.05.2024] /// - [System.Obsolete("Deprecated in 1.4")] + [System.Obsolete("Deprecated in 1.4, use ValueBox instead")] public DoubleValueBox DoubleValue => ValueBox; /// diff --git a/Source/Editor/CustomEditors/Elements/FloatValueElement.cs b/Source/Editor/CustomEditors/Elements/FloatValueElement.cs index 552e9d125..789d8966e 100644 --- a/Source/Editor/CustomEditors/Elements/FloatValueElement.cs +++ b/Source/Editor/CustomEditors/Elements/FloatValueElement.cs @@ -22,7 +22,7 @@ namespace FlaxEditor.CustomEditors.Elements /// /// [Deprecated on 26.05.2022, expires on 26.05.2024] /// - [System.Obsolete("Deprecated in 1.4, ValueBox instead")] + [System.Obsolete("Deprecated in 1.4, use ValueBox instead")] public FloatValueBox FloatValue => ValueBox; /// diff --git a/Source/Engine/Graphics/Mesh.cs b/Source/Engine/Graphics/Mesh.cs index 0a986d44d..68ff7e07f 100644 --- a/Source/Engine/Graphics/Mesh.cs +++ b/Source/Engine/Graphics/Mesh.cs @@ -339,7 +339,7 @@ namespace FlaxEngine /// The normal vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). /// The vertex colors (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(Vector3[] vertices, int[] triangles, Vector3[] normals = null, Vector3[] tangents = null, Vector2[] uv = null, Color32[] colors = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors); @@ -357,7 +357,7 @@ namespace FlaxEngine /// The normal vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). /// The vertex colors (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(List vertices, List triangles, List normals = null, List tangents = null, List uv = null, List colors = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors); @@ -375,7 +375,7 @@ namespace FlaxEngine /// The normal vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). /// The vertex colors (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(Vector3[] vertices, uint[] triangles, Vector3[] normals = null, Vector3[] tangents = null, Vector2[] uv = null, Color32[] colors = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors); @@ -393,7 +393,7 @@ namespace FlaxEngine /// The normal vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). /// The vertex colors (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(List vertices, List triangles, List normals = null, List tangents = null, List uv = null, List colors = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors); @@ -411,7 +411,7 @@ namespace FlaxEngine /// The tangent vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). /// The vertex colors (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(Vector3[] vertices, ushort[] triangles, Vector3[] normals = null, Vector3[] tangents = null, Vector2[] uv = null, Color32[] colors = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors); @@ -429,7 +429,7 @@ namespace FlaxEngine /// The tangent vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). /// The vertex colors (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(List vertices, List triangles, List normals = null, List tangents = null, List uv = null, List colors = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv), colors); diff --git a/Source/Engine/Graphics/SkinnedMesh.cs b/Source/Engine/Graphics/SkinnedMesh.cs index 8fb7a83dc..a7b7594bb 100644 --- a/Source/Engine/Graphics/SkinnedMesh.cs +++ b/Source/Engine/Graphics/SkinnedMesh.cs @@ -216,7 +216,7 @@ namespace FlaxEngine /// The normal vectors (per vertex). /// The normal vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(Vector3[] vertices, int[] triangles, Int4[] blendIndices, Vector4[] blendWeights, Vector3[] normals = null, Vector3[] tangents = null, Vector2[] uv = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, blendIndices, Utils.ConvertCollection(blendWeights), Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv)); @@ -235,7 +235,7 @@ namespace FlaxEngine /// The normal vectors (per vertex). /// The normal vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(Vector3[] vertices, uint[] triangles, Int4[] blendIndices, Vector4[] blendWeights, Vector3[] normals = null, Vector3[] tangents = null, Vector2[] uv = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, blendIndices, Utils.ConvertCollection(blendWeights), Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv)); @@ -254,7 +254,7 @@ namespace FlaxEngine /// The normal vectors (per vertex). /// The tangent vectors (per vertex). Use null to compute them from normal vectors. /// The texture coordinates (per vertex). - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void UpdateMesh(Vector3[] vertices, ushort[] triangles, Int4[] blendIndices, Vector4[] blendWeights, Vector3[] normals = null, Vector3[] tangents = null, Vector2[] uv = null) { UpdateMesh(Utils.ConvertCollection(vertices), triangles, blendIndices, Utils.ConvertCollection(blendWeights), Utils.ConvertCollection(normals), Utils.ConvertCollection(tangents), Utils.ConvertCollection(uv)); diff --git a/Source/Engine/Physics/CollisionData.cs b/Source/Engine/Physics/CollisionData.cs index 8b54c6218..e7f76a90f 100644 --- a/Source/Engine/Physics/CollisionData.cs +++ b/Source/Engine/Physics/CollisionData.cs @@ -19,7 +19,7 @@ namespace FlaxEngine /// The convex mesh generation flags. /// The convex mesh vertex limit. Use values in range [8;255] /// True if failed, otherwise false. - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public bool CookCollision(CollisionDataType type, Vector3[] vertices, uint[] triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { if (vertices == null) @@ -43,7 +43,7 @@ namespace FlaxEngine /// The convex mesh generation flags. /// The convex mesh vertex limit. Use values in range [8;255] /// True if failed, otherwise false. - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public bool CookCollision(CollisionDataType type, Vector3[] vertices, int[] triangles, ConvexMeshGenerationFlags convexFlags = ConvexMeshGenerationFlags.None, int convexVertexLimit = 255) { if (vertices == null) @@ -60,7 +60,7 @@ namespace FlaxEngine /// /// The output vertex buffer. /// The output index buffer. - [Obsolete("Deprecated in 1.4")] + [Obsolete("Deprecated in 1.4, use overload with Float3 and Float2 parameters")] public void ExtractGeometry(out Vector3[] vertexBuffer, out int[] indexBuffer) { ExtractGeometry(out Float3[] tmp, out indexBuffer); From 02a219a376d4362885f34a02a3c001f793e678db Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sun, 17 Sep 2023 17:05:20 +0300 Subject: [PATCH 03/15] Fix Editor viewport camera transformation getting corrupted when focused --- Source/Editor/Viewport/EditorViewport.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Viewport/EditorViewport.cs b/Source/Editor/Viewport/EditorViewport.cs index 13c06157a..e20069120 100644 --- a/Source/Editor/Viewport/EditorViewport.cs +++ b/Source/Editor/Viewport/EditorViewport.cs @@ -1119,7 +1119,12 @@ namespace FlaxEditor.Viewport var win = (WindowRootControl)Root; // Get current mouse position in the view - _viewMousePos = PointFromWindow(win.MousePosition); + { + // When the window is not focused, the position in window does not return sane values + Float2 pos = PointFromWindow(win.MousePosition); + if (!float.IsInfinity(pos.LengthSquared)) + _viewMousePos = pos; + } // Update input var window = win.Window; From f2c9ba5a00e56962d711b1768b08a83317a8f80b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 11 Oct 2023 15:33:32 -0500 Subject: [PATCH 04/15] Focus parent on value box slide end. --- Source/Editor/GUI/Input/ValueBox.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Editor/GUI/Input/ValueBox.cs b/Source/Editor/GUI/Input/ValueBox.cs index 492887611..321782a8e 100644 --- a/Source/Editor/GUI/Input/ValueBox.cs +++ b/Source/Editor/GUI/Input/ValueBox.cs @@ -182,6 +182,7 @@ namespace FlaxEditor.GUI.Input } SlidingEnd?.Invoke(); Defocus(); + Parent?.Focus(); } /// From 8eb9df9a18b928b197ec1cc77617a90f64a65c5f Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 11 Oct 2023 15:57:02 -0500 Subject: [PATCH 05/15] Change new anim port to TryGetBox. --- Source/Editor/Surface/Archetypes/Animation.cs | 20 ++++++++++++++----- .../Animations/Graph/AnimGroup.Animation.cpp | 17 +++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Animation.cs b/Source/Editor/Surface/Archetypes/Animation.cs index a05ede1e7..5743b2a84 100644 --- a/Source/Editor/Surface/Archetypes/Animation.cs +++ b/Source/Editor/Surface/Archetypes/Animation.cs @@ -59,8 +59,11 @@ namespace FlaxEditor.Surface.Archetypes if (Surface != null) { _assetSelect = GetChild(); - _assetBox = GetBox(8); - _assetSelect.Visible = !_assetBox.HasAnyConnection; + if (TryGetBox(8, out var box)) + { + _assetBox = box; + _assetSelect.Visible = !_assetBox.HasAnyConnection; + } UpdateTitle(); } } @@ -68,7 +71,11 @@ namespace FlaxEditor.Surface.Archetypes private void UpdateTitle() { var asset = Editor.Instance.ContentDatabase.Find((Guid)Values[0]); - Title = _assetBox.HasAnyConnection || asset == null ? "Animation" : asset.ShortName; + if (_assetBox != null) + Title = _assetBox.HasAnyConnection || asset == null ? "Animation" : asset.ShortName; + else + Title = asset?.ShortName ?? "Animation"; + var style = Style.Current; Resize(Mathf.Max(230, style.FontLarge.MeasureText(Title).X + 30), 160); } @@ -78,8 +85,11 @@ namespace FlaxEditor.Surface.Archetypes { base.ConnectionTick(box); - if (box.ID != _assetBox.ID) - return; + if (_assetBox != null) + { + if (box.ID != _assetBox.ID) + return; + } _assetSelect.Visible = !box.HasAnyConnection; UpdateTitle(); diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index a19b84370..6e4783d2c 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -764,14 +764,17 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu const float startTimePos = (float)tryGetValue(node->GetBox(7), node->Values[3]); // Override animation when animation reference box is connected - auto animationAssetBox = node->GetBox(8); - if (animationAssetBox->HasConnection()) + auto animationAssetBox = node->TryGetBox(8); + if (animationAssetBox) { - const Value assetBoxValue = tryGetValue(animationAssetBox, Value::Null); - if (assetBoxValue != Value::Null) - anim = (Animation*)assetBoxValue.AsAsset; - else - anim = nullptr; + if (animationAssetBox->HasConnection()) + { + const Value assetBoxValue = tryGetValue(animationAssetBox, Value::Null); + if (assetBoxValue != Value::Null) + anim = (Animation*)assetBoxValue.AsAsset; + else + anim = nullptr; + } } const float length = anim ? anim->GetLength() : 0.0f; From 28d6fe84efde592e384579c27059bca3d5b20f45 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 11 Oct 2023 16:17:59 -0500 Subject: [PATCH 06/15] Small change --- Source/Editor/Surface/Archetypes/Animation.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Animation.cs b/Source/Editor/Surface/Archetypes/Animation.cs index 5743b2a84..40a3d2a63 100644 --- a/Source/Editor/Surface/Archetypes/Animation.cs +++ b/Source/Editor/Surface/Archetypes/Animation.cs @@ -85,11 +85,10 @@ namespace FlaxEditor.Surface.Archetypes { base.ConnectionTick(box); - if (_assetBox != null) - { - if (box.ID != _assetBox.ID) - return; - } + if (_assetBox == null) + return; + if (box.ID != _assetBox.ID) + return; _assetSelect.Visible = !box.HasAnyConnection; UpdateTitle(); From e97ec74bf8035da4d09ad505b3e8d44981853643 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:37:04 -0400 Subject: [PATCH 07/15] clean code --- Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs | 4 +--- Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs | 4 ++-- Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs | 4 +--- Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs | 4 ++-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs b/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs index dd837fe00..c9a521734 100644 --- a/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs +++ b/Source/Editor/Tools/Terrain/PaintTerrainGizmo.cs @@ -153,9 +153,7 @@ namespace FlaxEditor.Tools.Terrain // Increase or decrease brush size with scroll if (Input.GetKey(KeyboardKeys.Shift)) { - var currentBrush = Mode.CurrentBrush; - currentBrush.Size += dt * currentBrush.Size * Input.Mouse.ScrollDelta * 5f; - Mode.CurrentBrush = currentBrush; + Mode.CurrentBrush.Size += dt * Mode.CurrentBrush.Size * Input.Mouse.ScrollDelta * 5f; } // Check if no terrain is selected diff --git a/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs index a68b90ce8..1d1bf87ca 100644 --- a/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs +++ b/Source/Editor/Tools/Terrain/PaintTerrainGizmoMode.cs @@ -139,9 +139,9 @@ namespace FlaxEditor.Tools.Terrain } /// - /// Gets or set the current brush. + /// Gets the current brush. /// - public Brush CurrentBrush { get => _brushes[(int)_brushType]; set => _brushes[(int)_brushType] = value; } + public Brush CurrentBrush => _brushes[(int)_brushType]; /// /// Gets the circle brush instance. diff --git a/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs b/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs index 837c86dcb..fef8bbf09 100644 --- a/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs +++ b/Source/Editor/Tools/Terrain/SculptTerrainGizmo.cs @@ -161,9 +161,7 @@ namespace FlaxEditor.Tools.Terrain // Increase or decrease brush size with scroll if (Input.GetKey(KeyboardKeys.Shift)) { - var currentBrush = Mode.CurrentBrush; - currentBrush.Size += dt * currentBrush.Size * Input.Mouse.ScrollDelta * 5f; - Mode.CurrentBrush = currentBrush; + Mode.CurrentBrush.Size += dt * Mode.CurrentBrush.Size * Input.Mouse.ScrollDelta * 5f; } // Check if selected terrain was changed during painting diff --git a/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs b/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs index b99ac135f..4b19cfbde 100644 --- a/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs +++ b/Source/Editor/Tools/Terrain/SculptTerrainGizmoMode.cs @@ -158,9 +158,9 @@ namespace FlaxEditor.Tools.Terrain } /// - /// Gets or set the current brush. + /// Gets the current brush. /// - public Brush CurrentBrush { get => _brushes[(int)_brushType]; set => _brushes[(int)_brushType] = value; } + public Brush CurrentBrush => _brushes[(int)_brushType]; /// /// Gets the circle brush instance. From b1ad2c3a02771ddd7d94f73a5c5a0476474c4517 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 12:10:21 +0200 Subject: [PATCH 08/15] Fix sprite shadow to match the sprite facing camera #1504 --- Source/Engine/UI/SpriteRender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/UI/SpriteRender.cpp b/Source/Engine/UI/SpriteRender.cpp index fb4f54e7f..25446c9c5 100644 --- a/Source/Engine/UI/SpriteRender.cpp +++ b/Source/Engine/UI/SpriteRender.cpp @@ -113,7 +113,7 @@ void SpriteRender::Draw(RenderContext& renderContext) auto model = _quadModel.As(); if (model->GetLoadedLODs() == 0) return; - const auto& view = renderContext.View; + const auto& view = (renderContext.LodProxyView ? *renderContext.LodProxyView : renderContext.View); Matrix m1, m2, m3, world; Matrix::Scaling(_size.X, _size.Y, 1.0f, m2); Matrix::RotationY(PI, m3); From 0175186c2783dd2f28ba9b39d3def897a2b40f62 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 12:17:55 +0200 Subject: [PATCH 09/15] Improve #1627 to return proper anim length --- .../Animations/Graph/AnimGroup.Animation.cpp | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 6e4783d2c..0518fe248 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -1,6 +1,7 @@ // Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #include "AnimGraph.h" +#include "Engine/Core/Types/VariantValueCast.h" #include "Engine/Content/Assets/Animation.h" #include "Engine/Content/Assets/SkeletonMask.h" #include "Engine/Content/Assets/AnimationGraphFunction.h" @@ -753,6 +754,13 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu auto anim = node->Assets[0].As(); auto& bucket = context.Data->State[node->BucketIndex].Animation; + // Override animation when animation reference box is connected + auto animationAssetBox = node->TryGetBox(8); + if (animationAssetBox && animationAssetBox->HasConnection()) + { + anim = TVariantValueCast::Cast(tryGetValue(animationAssetBox, Value::Null)); + } + switch (box->ID) { // Animation @@ -762,21 +770,6 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu const float speed = (float)tryGetValue(node->GetBox(5), node->Values[1]); const bool loop = (bool)tryGetValue(node->GetBox(6), node->Values[2]); const float startTimePos = (float)tryGetValue(node->GetBox(7), node->Values[3]); - - // Override animation when animation reference box is connected - auto animationAssetBox = node->TryGetBox(8); - if (animationAssetBox) - { - if (animationAssetBox->HasConnection()) - { - const Value assetBoxValue = tryGetValue(animationAssetBox, Value::Null); - if (assetBoxValue != Value::Null) - anim = (Animation*)assetBoxValue.AsAsset; - else - anim = nullptr; - } - } - const float length = anim ? anim->GetLength() : 0.0f; // Calculate new time position From b19bf57dfb0aba4d1306f7b5eab03a5e313d4434 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 13:10:34 +0200 Subject: [PATCH 10/15] Add logging any XAudio2 backed errors --- .../Audio/XAudio2/AudioBackendXAudio2.cpp | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp index f90c58875..988a1797a 100644 --- a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp +++ b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp @@ -27,7 +27,15 @@ #define MAX_INPUT_CHANNELS 2 #define MAX_OUTPUT_CHANNELS 8 #define MAX_CHANNELS_MATRIX_SIZE (MAX_INPUT_CHANNELS*MAX_OUTPUT_CHANNELS) - +#if BUILD_RELEASE +#define XAUDIO2_CHECK_ERROR(method) +#else +#define XAUDIO2_CHECK_ERROR(method) \ + if (hr != 0) \ + { \ + LOG(Error, "XAudio2 method {0} failed with error 0x{1:X} (at line {2})", TEXT(#method), hr, __LINE__ - 1); \ + } +#endif #define FLAX_COORD_SCALE 0.01f // units are meters #define FLAX_DST_TO_XAUDIO(x) x * FLAX_COORD_SCALE #define FLAX_POS_TO_XAUDIO(vec) X3DAUDIO_VECTOR(vec.X * FLAX_COORD_SCALE, vec.Y * FLAX_COORD_SCALE, vec.Z * FLAX_COORD_SCALE) @@ -263,10 +271,7 @@ namespace XAudio2 } const HRESULT hr = aSource->Voice->SubmitSourceBuffer(&buffer); - if (FAILED(hr)) - { - LOG(Warning, "XAudio2: Failed to submit source buffer (error: 0x{0:x})", hr); - } + XAUDIO2_CHECK_ERROR(SubmitSourceBuffer); } void VoiceCallback::OnBufferEnd(void* pBufferContext) @@ -391,12 +396,10 @@ void AudioBackendXAudio2::Source_OnAdd(AudioSource* source) 1, &aSource->Destination }; - const HRESULT hr = XAudio2::Instance->CreateSourceVoice(&aSource->Voice, &aSource->Format, 0, 2.0f, &aSource->Callback, &sendList); + HRESULT hr = XAudio2::Instance->CreateSourceVoice(&aSource->Voice, &aSource->Format, 0, 2.0f, &aSource->Callback, &sendList); + XAUDIO2_CHECK_ERROR(CreateSourceVoice); if (FAILED(hr)) - { - LOG(Error, "Failed to create XAudio2 voice. Error: 0x{0:x}", hr); return; - } // Prepare source state aSource->Callback.Source = source; @@ -410,7 +413,8 @@ void AudioBackendXAudio2::Source_OnAdd(AudioSource* source) aSource->DopplerFactor = source->GetDopplerFactor(); aSource->UpdateTransform(source); aSource->UpdateVelocity(source); - aSource->Voice->SetVolume(source->GetVolume()); + hr = aSource->Voice->SetVolume(source->GetVolume()); + XAUDIO2_CHECK_ERROR(SetVolume); // 0 is invalid ID so shift them sourceID++; @@ -451,7 +455,8 @@ void AudioBackendXAudio2::Source_VolumeChanged(AudioSource* source) auto aSource = XAudio2::GetSource(source); if (aSource && aSource->Voice) { - aSource->Voice->SetVolume(source->GetVolume()); + const HRESULT hr = aSource->Voice->SetVolume(source->GetVolume()); + XAUDIO2_CHECK_ERROR(SetVolume); } } @@ -494,11 +499,16 @@ void AudioBackendXAudio2::Source_IsLoopingChanged(AudioSource* source) XAudio2::Buffer* aBuffer = XAudio2::Buffers[bufferId - 1]; XAudio2::Locker.Unlock(); + HRESULT hr; const bool isPlaying = source->IsActuallyPlayingSth(); if (isPlaying) - aSource->Voice->Stop(); + { + hr = aSource->Voice->Stop(); + XAUDIO2_CHECK_ERROR(Stop); + } - aSource->Voice->FlushSourceBuffers(); + hr = aSource->Voice->FlushSourceBuffers(); + XAUDIO2_CHECK_ERROR(FlushSourceBuffers); aSource->LastBufferStartSamplesPlayed = 0; aSource->BuffersProcessed = 0; @@ -517,7 +527,10 @@ void AudioBackendXAudio2::Source_IsLoopingChanged(AudioSource* source) XAudio2::QueueBuffer(aSource, source, bufferId, buffer); if (isPlaying) - aSource->Voice->Start(); + { + hr = aSource->Voice->Start(); + XAUDIO2_CHECK_ERROR(Start); + } } void AudioBackendXAudio2::Source_SpatialSetupChanged(AudioSource* source) @@ -572,7 +585,8 @@ void AudioBackendXAudio2::Source_Play(AudioSource* source) if (aSource && aSource->Voice && !aSource->IsPlaying) { // Play - aSource->Voice->Start(); + const HRESULT hr = aSource->Voice->Start(); + XAUDIO2_CHECK_ERROR(Start); aSource->IsPlaying = true; } } @@ -583,7 +597,8 @@ void AudioBackendXAudio2::Source_Pause(AudioSource* source) if (aSource && aSource->Voice && aSource->IsPlaying) { // Pause - aSource->Voice->Stop(); + const HRESULT hr = aSource->Voice->Stop(); + XAUDIO2_CHECK_ERROR(Stop); aSource->IsPlaying = false; } } @@ -596,11 +611,13 @@ void AudioBackendXAudio2::Source_Stop(AudioSource* source) aSource->StartTime = 0.0f; // Pause - aSource->Voice->Stop(); + HRESULT hr = aSource->Voice->Stop(); + XAUDIO2_CHECK_ERROR(Stop); aSource->IsPlaying = false; // Unset streaming buffers to rewind - aSource->Voice->FlushSourceBuffers(); + hr = aSource->Voice->FlushSourceBuffers(); + XAUDIO2_CHECK_ERROR(FlushSourceBuffers); aSource->BuffersProcessed = 0; aSource->Callback.PeekSamples(); } @@ -697,10 +714,7 @@ void AudioBackendXAudio2::Source_DequeueProcessedBuffers(AudioSource* source) if (aSource && aSource->Voice) { const HRESULT hr = aSource->Voice->FlushSourceBuffers(); - if (FAILED(hr)) - { - LOG(Warning, "XAudio2: FlushSourceBuffers failed. Error: 0x{0:x}", hr); - } + XAUDIO2_CHECK_ERROR(FlushSourceBuffers); aSource->BuffersProcessed = 0; } } @@ -779,7 +793,8 @@ void AudioBackendXAudio2::Base_SetVolume(float value) { if (XAudio2::MasteringVoice) { - XAudio2::MasteringVoice->SetVolume(value); + const HRESULT hr = XAudio2::MasteringVoice->SetVolume(value); + XAUDIO2_CHECK_ERROR(SetVolume); } } From 749c0cacb40c0175cbe9533f314bcb4a7f717862 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 13:11:07 +0200 Subject: [PATCH 11/15] Fix audio playback in XAudio2 when clip is 3D but source is 2D --- Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp index 988a1797a..1998b8e5e 100644 --- a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp +++ b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp @@ -380,7 +380,7 @@ void AudioBackendXAudio2::Source_OnAdd(AudioSource* source) const auto& header = clip->AudioHeader; auto& format = aSource->Format; format.wFormatTag = WAVE_FORMAT_PCM; - format.nChannels = source->Is3D() ? 1 : header.Info.NumChannels; // 3d audio is always mono (AudioClip auto-converts before buffer write) + format.nChannels = clip->Is3D() ? 1 : header.Info.NumChannels; // 3d audio is always mono (AudioClip auto-converts before buffer write) format.nSamplesPerSec = header.Info.SampleRate; format.wBitsPerSample = header.Info.BitDepth; format.nBlockAlign = (WORD)(format.nChannels * (format.wBitsPerSample / 8)); From 2671e3881fd1cf95532c877f2c85e03388116560 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 14:03:13 +0200 Subject: [PATCH 12/15] Add `Spacebar` to toggle play/pause in Audio Clip window --- Source/Editor/Windows/Assets/AudioClipWindow.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Source/Editor/Windows/Assets/AudioClipWindow.cs b/Source/Editor/Windows/Assets/AudioClipWindow.cs index 8cf31f416..b1d9796dc 100644 --- a/Source/Editor/Windows/Assets/AudioClipWindow.cs +++ b/Source/Editor/Windows/Assets/AudioClipWindow.cs @@ -335,6 +335,22 @@ namespace FlaxEditor.Windows.Assets } } + /// + public override bool OnKeyDown(KeyboardKeys key) + { + if (base.OnKeyDown(key)) + return true; + + if (key == KeyboardKeys.Spacebar) + { + if (_previewSource?.State == AudioSource.States.Playing) + OnPause(); + else + OnPlay(); + } + return false; + } + /// public override bool UseLayoutData => true; From 69fb2c331f2d8966090ef29f97a98dcde24cd6c5 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 14:03:43 +0200 Subject: [PATCH 13/15] Minor improvements to audio --- Source/Engine/Audio/AudioSource.cpp | 1 - Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index afe5c4b49..cb32e0967 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -187,7 +187,6 @@ float AudioSource::GetTime() const return 0.0f; float time = AudioBackend::Source::GetCurrentBufferTime(this); - ASSERT(time >= 0.0f && time <= Clip->GetLength()); if (UseStreaming()) { diff --git a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp index 1998b8e5e..c857b4064 100644 --- a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp +++ b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp @@ -27,14 +27,14 @@ #define MAX_INPUT_CHANNELS 2 #define MAX_OUTPUT_CHANNELS 8 #define MAX_CHANNELS_MATRIX_SIZE (MAX_INPUT_CHANNELS*MAX_OUTPUT_CHANNELS) -#if BUILD_RELEASE -#define XAUDIO2_CHECK_ERROR(method) -#else +#if ENABLE_ASSERTION #define XAUDIO2_CHECK_ERROR(method) \ if (hr != 0) \ { \ LOG(Error, "XAudio2 method {0} failed with error 0x{1:X} (at line {2})", TEXT(#method), hr, __LINE__ - 1); \ } +#else +#define XAUDIO2_CHECK_ERROR(method) #endif #define FLAX_COORD_SCALE 0.01f // units are meters #define FLAX_DST_TO_XAUDIO(x) x * FLAX_COORD_SCALE @@ -112,7 +112,9 @@ namespace XAudio2 COM_DECLSPEC_NOTHROW void STDMETHODCALLTYPE OnVoiceError(THIS_ void* pBufferContext, HRESULT Error) override { +#if ENABLE_ASSERTION LOG(Warning, "IXAudio2VoiceCallback::OnVoiceError! Error: 0x{0:x}", Error); +#endif } public: From 4ac65ee91cea59f03344688f147548d8f047fddb Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 14:31:41 +0200 Subject: [PATCH 14/15] Fix audio preview for multi-channel audio clips --- Source/Editor/Viewport/Previews/AudioClipPreview.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/Viewport/Previews/AudioClipPreview.cs b/Source/Editor/Viewport/Previews/AudioClipPreview.cs index 446cef657..3235cd194 100644 --- a/Source/Editor/Viewport/Previews/AudioClipPreview.cs +++ b/Source/Editor/Viewport/Previews/AudioClipPreview.cs @@ -171,7 +171,7 @@ namespace FlaxEditor.Viewport.Previews case DrawModes.Fill: clipsInView = 1.0f; clipWidth = width; - samplesPerIndex = (uint)(samplesPerChannel / width); + samplesPerIndex = (uint)(samplesPerChannel / width) * info.NumChannels; break; case DrawModes.Single: clipsInView = Mathf.Min(clipsInView, 1.0f); From 455b3f2446b7694bb66dae9da54ae9bf5dae835d Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Oct 2023 15:20:23 +0200 Subject: [PATCH 15/15] Fix XAudio2 playback when seeking audio start play location --- .../Audio/XAudio2/AudioBackendXAudio2.cpp | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp index c857b4064..3092a2229 100644 --- a/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp +++ b/Source/Engine/Audio/XAudio2/AudioBackendXAudio2.cpp @@ -31,7 +31,7 @@ #define XAUDIO2_CHECK_ERROR(method) \ if (hr != 0) \ { \ - LOG(Error, "XAudio2 method {0} failed with error 0x{1:X} (at line {2})", TEXT(#method), hr, __LINE__ - 1); \ + LOG(Error, "XAudio2 method {0} failed with error 0x{1:X} (at line {2})", TEXT(#method), (uint32)hr, __LINE__ - 1); \ } #else #define XAUDIO2_CHECK_ERROR(method) @@ -131,7 +131,8 @@ namespace XAudio2 XAUDIO2_SEND_DESCRIPTOR Destination; float Pitch; float Pan; - float StartTime; + float StartTimeForQueueBuffer; + float LastBufferStartTime; float DopplerFactor; uint64 LastBufferStartSamplesPlayed; int32 BuffersProcessed; @@ -155,7 +156,8 @@ namespace XAudio2 Destination.pOutputVoice = nullptr; Pitch = 1.0f; Pan = 0.0f; - StartTime = 0.0f; + StartTimeForQueueBuffer = 0.0f; + LastBufferStartTime = 0.0f; IsDirty = false; Is3D = false; IsPlaying = false; @@ -265,11 +267,14 @@ namespace XAudio2 buffer.pAudioData = aBuffer->Data.Get(); buffer.AudioBytes = aBuffer->Data.Count(); - if (aSource->StartTime > ZeroTolerance) + if (aSource->StartTimeForQueueBuffer > ZeroTolerance) { - buffer.PlayBegin = (UINT32)(aSource->StartTime * (aBuffer->Info.SampleRate * aBuffer->Info.NumChannels)); - buffer.PlayLength = aBuffer->Info.NumSamples / aBuffer->Info.NumChannels - buffer.PlayBegin; - aSource->StartTime = 0; + // Offset start position when playing buffer with a custom time offset + const uint32 bytesPerSample = aBuffer->Info.BitDepth / 8 * aBuffer->Info.NumChannels; + buffer.PlayBegin = (UINT32)(aSource->StartTimeForQueueBuffer * aBuffer->Info.SampleRate); + buffer.PlayLength = (buffer.AudioBytes / bytesPerSample) - buffer.PlayBegin; + aSource->LastBufferStartTime = aSource->StartTimeForQueueBuffer; + aSource->StartTimeForQueueBuffer = 0; } const HRESULT hr = aSource->Voice->SubmitSourceBuffer(&buffer); @@ -512,6 +517,7 @@ void AudioBackendXAudio2::Source_IsLoopingChanged(AudioSource* source) hr = aSource->Voice->FlushSourceBuffers(); XAUDIO2_CHECK_ERROR(FlushSourceBuffers); aSource->LastBufferStartSamplesPlayed = 0; + aSource->LastBufferStartTime = 0; aSource->BuffersProcessed = 0; XAUDIO2_BUFFER buffer = { 0 }; @@ -524,7 +530,7 @@ void AudioBackendXAudio2::Source_IsLoopingChanged(AudioSource* source) const UINT32 totalSamples = aBuffer->Info.NumSamples / aBuffer->Info.NumChannels; buffer.PlayBegin = state.SamplesPlayed % totalSamples; buffer.PlayLength = totalSamples - buffer.PlayBegin; - aSource->StartTime = 0; + aSource->StartTimeForQueueBuffer = 0; XAudio2::QueueBuffer(aSource, source, bufferId, buffer); @@ -610,7 +616,8 @@ void AudioBackendXAudio2::Source_Stop(AudioSource* source) auto aSource = XAudio2::GetSource(source); if (aSource && aSource->Voice) { - aSource->StartTime = 0.0f; + aSource->StartTimeForQueueBuffer = 0.0f; + aSource->LastBufferStartTime = 0.0f; // Pause HRESULT hr = aSource->Voice->Stop(); @@ -620,6 +627,7 @@ void AudioBackendXAudio2::Source_Stop(AudioSource* source) // Unset streaming buffers to rewind hr = aSource->Voice->FlushSourceBuffers(); XAUDIO2_CHECK_ERROR(FlushSourceBuffers); + Platform::Sleep(10); // TODO: find a better way to handle case when VoiceCallback::OnBufferEnd is called after source was stopped thus BuffersProcessed != 0, probably via buffers contexts ptrs aSource->BuffersProcessed = 0; aSource->Callback.PeekSamples(); } @@ -631,7 +639,7 @@ void AudioBackendXAudio2::Source_SetCurrentBufferTime(AudioSource* source, float if (aSource) { // Store start time so next buffer submitted will start from here (assumes audio is stopped) - aSource->StartTime = value; + aSource->StartTimeForQueueBuffer = value; } } @@ -647,8 +655,9 @@ float AudioBackendXAudio2::Source_GetCurrentBufferTime(const AudioSource* source aSource->Voice->GetState(&state); const uint32 numChannels = clipInfo.NumChannels; const uint32 totalSamples = clipInfo.NumSamples / numChannels; + const uint32 sampleRate = clipInfo.SampleRate;// / clipInfo.NumChannels; state.SamplesPlayed -= aSource->LastBufferStartSamplesPlayed % totalSamples; // Offset by the last buffer start to get time relative to its begin - time = aSource->StartTime + (state.SamplesPlayed % totalSamples) / static_cast(Math::Max(1U, clipInfo.SampleRate)); + time = aSource->LastBufferStartTime + (state.SamplesPlayed % totalSamples) / static_cast(Math::Max(1U, sampleRate)); } return time; } @@ -765,8 +774,7 @@ void AudioBackendXAudio2::Buffer_Write(uint32 bufferId, byte* samples, const Aud XAudio2::Buffer* aBuffer = XAudio2::Buffers[bufferId - 1]; XAudio2::Locker.Unlock(); - const uint32 bytesPerSample = info.BitDepth / 8; - const int32 samplesLength = info.NumSamples * bytesPerSample; + const uint32 samplesLength = info.NumSamples * info.BitDepth / 8; aBuffer->Info = info; aBuffer->Data.Set(samples, samplesLength);