Welcome, Guest! Login | Register
Major memory leak when loading projects in 3D Rad
Info
Report
193 Posts

Hello there, as a follow up to the off-topic discussion in Kulu's game project, I decided to continue the topic here.

I will divide my post into 8 sections.

1.) Intro (why I'm doing this?)
2.) How I replicated/triggered the memory leak(s)
3.) Other ways this bug exists
4.) Final memory reports
5.) Interesting stuff I found while trying to provoke the leak(s)
6.) Why I think this memory leak exists.
7.) Tips for persons still using 3D Rad v7.22
8.) Things to debate here.

1.)Intro

Now, by the title, I also found some interesting stuff related to 3D Rad bugs (memory leaks and etc).  Now, of course, you might say, I'm losing my time and etc. The deal is that I'm still passionate about this engine (since I made games in it when I was like 12 years old + the reason I'm working on 3DRadSpace lol), and of course, I'm interested in finding how it works and all these details.

A second reason, is that we were going off-topic from Kulu's showcase forum thread. As I and @thelurker we talked about while I was writing this long post.

A third reason, are the things I found very interesting
while I was playing around with 3D Rad's editor.

2.) How I replicated/triggered the memory leak(s)

First of all, getting into the topic - I managed to crash 3D Rad by loading ~55 different projects (+1 accidental project reload + something else I will talk about later). These were
AircraftAGL.3dr
AircraftDemo.3dr
AircraftDemo_autobalance.3dr
.
.
.
NetBallArenaServer.3dr (3D Rad crashed here)
And yes, I opened all projects in alphabetical order. And I played each project for a time between 1 minute to 5 minutes.  Not gonna lie, it was fun watching the memory usage counter go up.

3.) Other ways this bug exists:
   I also found out that this memory leak can be triggered by using 3D Rad's Undo-Redo implementation. If anyone ever used Ctrl+Z or Ctrl+X in 3D Rad, you can see that it reloads the project. (In my honest opinion, that's a baaad implementation, since you'd prefer using nodes, instead of multiple projects).
The undo-redo files are saved at:
	(INSERT 3D RAD'S ROOT DIRECTORY)DRad_res\system\undo]
saved with the filename
undo_0[number].3dr
with the numbers being in the range from 0 to 31. Allowing 32 undo-redo levels. That might be trivial, but some people might not know.

   Addons can trigger this, but I didn't test this case. I will update with a second post in this thread.

4.) Final memory reports

    Before 3D Rad crashed, probably with an error irrelevant to the memory leak by the way - I managed to make 3D Rad have a ~1.5 GB memory load. Damn, that's an interesting number.
    I wish I could save the `Visual Studio Debugging Snapshots` but I did a number of 68 snapshots, each containing how much memory was allocated or lost since the startup (if first snapshot) or previous snapshot. Too bad I apparently lost all of them, and all my remaining proof is few Discord screenshots.

   There's an interesting side case to this - where strictly 2D projects will not provoke the memory leak (for example EOL + Sprites + Scripts). (24 and 25 snapshots)
  
   During playing, there seems to be a minor memory leak from the physics engine? I've also seen heap memory getting deallocated during playing, so I can't know for sure. See the 30th snapshot in the provided screenshot(s).

   When 3D Rad crashed, VS Debugger paused the process, I opened up Task Manager claiming I have 300 MBs of used memory. Is Task Manager lying? (See the next section why this might be true?)

5.) Interesting stuff I found while trying to provoke the leak(s)

    While approaching the crash, I've seen artifacts on the textures on the loaded models. See screenshots at the bottom of the post.

a. Terrain being almost completely white, but I still could see some details when zooming in?
b. Skybox being completely white too. (triggered when loading the LODDemo.3dr).

These two may mean that the ID3D9Device couldn't allocate memory for the ID3D9Texture(s) since the memory was running out. Assuming 3D Rad and 3Impact are build using the DirectX 9 graphics API.

   There was also a weird issue with Windows 10 not allowing me to screenshot the white skybox artifact. This being OS-related, this fact is out of the equation.

6.) Why I think this memory leak exists.

By definition, a memory leak exists if the program or code allocates memory and the dynamic memory doesn't get deallocated until the program exits. (the OS deallocating the program's memory.)

Apparently, when 3D Rad is opening a project, it allocated memory space for the objects to fit in a list. It can also allocate the list again, to keep the original states in check, to implement the iObjectReset(int) function.

I think that Fernando didn't think/ didn't bother writing code to deallocate the resources used by the loaded objects. Or he did but it doesn't work for non-2D objects? Are vertex buffers data structures being leaked? Well, this is only speculation at this point, since reverse engineering will be needed to find out.

7.) Tips for persons still using 3D Rad v7.22

Tip #1: Avoid loading multiple projects, use as few projects as possible. 3D Rad's load times are horrendous on HDD's anyways. I recommend using iObjectRefresh(int,string) to load maps from other levels, and try using Imposters for the level elements (pickups, props).

Tip #2: Use as many Script objects as possible. Some objects take more or less time to load. The script object, as far as I know, has one of the shortest load times.

Tip #3: Try to aim for small games in 3D Rad. That's even what 3D Rad's goal is - making small games as fast as possible - even Fernando said it (I can't find the source, maybe I'm too lazy lol).

Tip #4: Use 3DRadSpace
  Or any other game engine, if you want to avoid 3D Rad's issues.

8.) Things to debate here.

I'd like to see other people replicating my experience, also clearing some stuff up. For example, giving ideas why some stuff happens and why not. Also the classical debate "Unity good, 3D Rad bad".
Created on: 1 month ago
Edited on: 1 month ago
Info
Report
319 Posts

Also the classical debate "Unity good, 3D Rad bad"

Unity is just an example out of all up-to-date engines available for use. Even 3D Rad Space has more perspective than 3D Rad itself just for the sole reason that it's actively supported (by your means at the time of this post). Whether it's a viable choice in terms of stability and feature availability is another topic.

It's not a 100% guarantee that a supported software is going to get any more stable with time. However, it's for sure guaranteed that an unsupported software will get worse. With supported software, there's always hope that an issue will eventually be fixed. With unsupported, you are stuck with it forever.

I want to emphasize on the word actively supported as much as I can, as I am being misunderstood when I am talking about Unity vs 3D Rad. I'm not solely advocating for Unity just because it's Unity. Any other engine would do - Unreal, CryEngine, Godot (popular actively developed alternatives). Just move on to something worth investing your time into.
Created on: 1 month ago
Info
Report
73 Posts

whaddaya mean 3drad is not 'actively supported' it's supported by the community now, we may not be able to fix it internally but we can certainly make workarounds to make it run better then it ever did before, and no updates means no new, unexpected bugs to contend with.

@athanatos, you went off on a tangent i didn't expect, kulu meant COMPILED level loads, not editor loads, but nice find that it has same issues. it's easily solved by loading projects from explorer [instead of in-editor's open dialog] then close to load another, which i mostly have done anyway, and i rarely use undo.

i made another thread for compiled loads here: https://classdev.net/page/thread/1L3d36_siPEJ5z52/compiled-multilevel-load-ram-leaks-fix
Created on: 1 month ago
Edited on: 1 month ago
Info
Report
193 Posts

Quote from: thelurker

@athanatos, you went off on a tangent i didn't expect, kulu meant COMPILED level loads, not editor loads, but nice find that it has same issues. it's easily solved by loading projects from explorer [instead of in-editor's open dialog] then close to load another, which i mostly have done anyway, and i rarely use undo.


Game engine editors and game engine compiled projects share the same base (most cases) (unless the editor is OOP based and the compiled enviorement is ECS-based, this being a rare case in my opinion). It was the easiest move to debug the engine firstly.
Created on: 1 month ago
Edited on: 1 month ago
Reply
Preview
Post
Or use the advanced reply form here...
Sponsored