Browse Source

Fixed heap corruption that would happen when a Material was destroyed but GpuParamBlockBuffer was still being used on the core thread. Material was incorrectly force destroying the buffer without regard for its reference count.
Fixed a small issue with debug rendering

Marko Pintera 12 years ago
parent
commit
9d279ed662

+ 23 - 7
BansheeEngine/Source/BsDrawHelper.cpp

@@ -76,7 +76,7 @@ namespace BansheeEngine
 
 		outIndices += indexOffset;
 		outIndices[0] = vertexOffset + 0;
-		outIndices[1] = vertexOffset + 2;
+		outIndices[1] = vertexOffset + 1;
 	}
 
 	void DrawHelper::line2D_Pixel(const CM::Vector2& a, const CM::Vector2& b, const CM::Color& color, const MeshDataPtr& meshData, CM::UINT32 vertexOffset, CM::UINT32 indexOffset)
@@ -114,10 +114,10 @@ namespace BansheeEngine
 		Vector2 v2 = b + dir + nrm;
 		Vector2 v3 = b + dir - nrm;
 
-		points.push_back(v0);
-		points.push_back(v1);
-		points.push_back(v2);
-		points.push_back(v3);
+		points[0] = v0;
+		points[1] = v1;
+		points[2] = v2;
+		points[3] = v3;
 
 		polygon2D_AA(points, width, color, outVertices, outColors, vertexOffset, vertexStride, outIndices, indexOffset);
 	}
@@ -303,7 +303,15 @@ namespace BansheeEngine
 
 		meshData->endDesc();
 
-		line2D_Pixel(a, b, color, meshData, 0, 0);
+		Vector2 actualA = a;
+		Vector2 actualB = b;
+		if(coordType == CoordType::Normalized)
+		{
+			actualA = normalizedCoordToClipSpace(a);
+			actualB = normalizedCoordToClipSpace(b);
+		}
+
+		line2D_Pixel(actualA, actualB, color, meshData, 0, 0);
 
 		HMesh mesh = Mesh::create();
 
@@ -345,7 +353,15 @@ namespace BansheeEngine
 
 		meshData->endDesc();
 
-		line2D_AA(a, b, width, color, meshData, 0, 0);
+		Vector2 actualA = a;
+		Vector2 actualB = b;
+		if(coordType == CoordType::Normalized)
+		{
+			actualA = normalizedCoordToClipSpace(a);
+			actualB = normalizedCoordToClipSpace(b);
+		}
+
+		line2D_AA(actualA, actualB, width, color, meshData, 0, 0);
 
 		HMesh mesh = Mesh::create();
 

+ 0 - 1
CamelotClient/CamelotClient.cpp

@@ -29,7 +29,6 @@
 #include "BsMainEditorWindow.h"
 // End editor includes
 
-
 #include "CmDebugCamera.h"
 #include "DbgEditorWidget1.h"
 #include "DbgEditorWidget2.h"

+ 6 - 2
CamelotClient/Source/BsMainEditorWindow.cpp

@@ -39,8 +39,12 @@ namespace BansheeEditor
 
 		textSprite->init(sceneCamera, "Testing in a new row, does this work?", nullptr);
 
-		DrawHelper::instance().drawQuad2D(sceneCamera, FRect(0.0f, 0.2f, 0.75f, 0.5f), Color::White, CoordType::Normalized, 50.0f);
-		DrawHelper::instance().drawQuad2D(sceneCamera, FRect(50.0f, 50.0f, 100.0f, 50.0f), Color::Blue, CoordType::Pixel, 50.0f);
+		DrawHelper::instance().drawQuad2D(sceneCamera, FRect(0.0f, 0.2f, 0.75f, 0.5f), Color::White, CoordType::Normalized, 250.0f);
+		DrawHelper::instance().drawQuad2D(sceneCamera, FRect(50.0f, 50.0f, 100.0f, 50.0f), Color::Blue, CoordType::Pixel, 250.0f);
+
+		DrawHelper::instance().drawLine2D_Pixel(sceneCamera, Vector2(0, 0), Vector2(20, 20), Color::Blue, CoordType::Pixel, 250.0f);
+
+		DrawHelper::instance().drawLine2D_AA(sceneCamera, Vector2(100, 0), Vector2(120, 20), 5.0f, Color::Blue, CoordType::Pixel, 250.0f);
 	}
 
 	MainEditorWindow::~MainEditorWindow()

+ 0 - 5
CamelotCore/Source/CmMaterial.cpp

@@ -890,11 +890,6 @@ namespace CamelotFramework
 
 	void Material::freeParamBuffers()
 	{
-		for(auto& buffer : mParamBuffers)
-		{
-			buffer->destroy();
-		}
-
 		mParamBuffers.clear();
 	}
 

+ 1 - 1
CamelotD3D11RenderSystem/Include/CmD3D11RenderSystem.h

@@ -110,7 +110,7 @@ namespace CamelotFramework
 		IDXGIFactory*		mDXGIFactory;
 		D3D11Device*		mDevice;
 
-		D3D11DriverList*	mDriverList;
+		D3D11DriverList*	mDriverList;
 		D3D11Driver*		mActiveD3DDriver;
 
 		D3D_FEATURE_LEVEL	mFeatureLevel;

+ 20 - 1
DrawHelper.txt

@@ -15,4 +15,23 @@ Add class DrawHelper:
 
 --------------------------
 
- Only one material per viewport needs to exist, no need for separate material for each element
+ Only one material per viewport needs to exist, no need for separate material for each element
+
+-------------------------
+
+ There's an issue with GPuParamBlockBuffer::writeData. Data is trying to be written but buffer is uninitialized! Happens with DX11
+ DX9 reports a memory heap corruption
+ - Both of these seems to be related to DrawHelper::render and don't seem to happen if I comment it out
+ - My best guess is that Material::setFloat for ScreenSpace shader is not working properly
+   - ISsue possibly being that minimum amount of space allocated by the shader is 16 bytes, but ScreenSpace shader needs only 2
+   - This doubt is further confirmed by the crash not happening when I comment out the screen space rendering
+
+AA lines render but look a bit off.
+
+Vertex colors dont match between DX11/GL and DX9. DX9 seems to expect BGRA
+
+---------
+
+Num verts/indices for polygon2d_AA method:
+(n * 2) vertices
+(n * 6) + max(0, n - 2) * 3