-
Notifications
You must be signed in to change notification settings - Fork 32
Fix numerous TE memory issues #1164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
11600f7
6b765a0
3d50264
bf342b1
f70582f
4480972
e453a48
cca21b8
c24bbe2
eafb0ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,12 +144,14 @@ Room[] CollectRoomsToDraw() | |
| // Collect rooms to draw | ||
| var camPos = Camera.GetPosition(); | ||
| var roomsToDraw = CollectRoomsToDraw(_editor.SelectedRoom).ToArray(); | ||
| var roomsToDrawDistanceSquared = new float[roomsToDraw.Length]; | ||
|
|
||
| if (_roomsDistanceCache == null || _roomsDistanceCache.Length < roomsToDraw.Length) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand correctly, even if now
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I've pushed a fix for this. |
||
| _roomsDistanceCache = new float[roomsToDraw.Length]; | ||
|
|
||
| for (int i = 0; i < roomsToDraw.Length; ++i) | ||
| roomsToDrawDistanceSquared[i] = Vector3.DistanceSquared(camPos, roomsToDraw[i].WorldPos + roomsToDraw[i].GetLocalCenter()); | ||
| _roomsDistanceCache[i] = Vector3.DistanceSquared(camPos, roomsToDraw[i].WorldPos + roomsToDraw[i].GetLocalCenter()); | ||
|
|
||
| Array.Sort(roomsToDrawDistanceSquared, roomsToDraw); | ||
| Array.Sort(_roomsDistanceCache, roomsToDraw, 0, roomsToDraw.Length); | ||
| Array.Reverse(roomsToDraw); | ||
|
|
||
| return roomsToDraw; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,10 +16,12 @@ | |
|
|
||
| namespace TombLib.LevelData | ||
| { | ||
| public class ImportedGeometryTexture : Texture | ||
| public class ImportedGeometryTexture : Texture, IDisposable | ||
| { | ||
| public Texture2D DirectXTexture { get; private set; } | ||
|
|
||
| private bool _disposed; | ||
|
|
||
|
Nickelony marked this conversation as resolved.
|
||
| public ImportedGeometryTexture(string absolutePath) | ||
| { | ||
| AbsolutePath = absolutePath; | ||
|
|
@@ -31,22 +33,39 @@ public ImportedGeometryTexture(string absolutePath) | |
| if (SynchronizationContext.Current == null) | ||
| DirectXTexture = TextureLoad.Load(ImportedGeometry.Device, Image); | ||
| else | ||
| SynchronizationContext.Current.Post(unused => // Synchronize DirectX, we can't 'send' because that may deadlock with the level settings reloader | ||
| DirectXTexture = TextureLoad.Load(ImportedGeometry.Device, Image), null); | ||
| SynchronizationContext.Current.Post(unused => { | ||
|
Lwmte marked this conversation as resolved.
|
||
| if (_disposed) | ||
| return; | ||
|
|
||
| DirectXTexture = TextureLoad.Load(ImportedGeometry.Device, Image); | ||
|
Nickelony marked this conversation as resolved.
|
||
| }, null); | ||
| } | ||
|
|
||
| private ImportedGeometryTexture(ImportedGeometryTexture other) | ||
| { | ||
| DirectXTexture = other.DirectXTexture; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this assignment now happening elsewhere, or not needed?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an ownership problem, since
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot From my initial analysis, the clones of the textures are purely for data driven operations, and the DX texture itself doesn't need to be copied, but I please double-check this claim and whether the DX texture not being copied causes any new issues/regressions.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified - removing Analysis:
Key points:
The change is correct and improves ownership semantics. |
||
| AbsolutePath = other.AbsolutePath; | ||
| Image = other.Image; | ||
| } | ||
|
|
||
| public void Assign(ImportedGeometryTexture other) | ||
| { | ||
| // Dispose old GPU texture if it differs from the new one. | ||
| if (DirectXTexture != null && DirectXTexture != other.DirectXTexture) | ||
| DirectXTexture.Dispose(); | ||
|
|
||
| AbsolutePath = other.AbsolutePath; | ||
| Image = other.Image; | ||
| DirectXTexture = other.DirectXTexture; | ||
|
|
||
| _disposed = false; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _disposed = true; | ||
|
|
||
| DirectXTexture?.Dispose(); | ||
| DirectXTexture = null; | ||
| } | ||
|
Nickelony marked this conversation as resolved.
|
||
|
|
||
| public override Texture Clone() => new ImportedGeometryTexture(this); | ||
|
Nickelony marked this conversation as resolved.
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.