godot icon indicating copy to clipboard operation
godot copied to clipboard

GLTF export crashing upon exceeding allocations

Open stryker313 opened this issue 4 years ago • 7 comments

Godot version

v3.4.beta3.official

System information

Windows 10 GTX 1060 6gb Intel 4690k

Issue description

GLTF Export crashing upon use. Trying to export with either gltf or glb results in crash and no file.

Steps to reproduce

Open MeshSmall.tscn Export to any directory you want Editor Will Crash.

Minimal reproduction project

GLTF EXPORT BUG.zip

stryker313 avatar Aug 18 '21 19:08 stryker313

See also https://github.com/godotengine/godot/issues/51132.

Calinou avatar Aug 18 '21 19:08 Calinou

The scene is too large, it needs 64662 GLTFAccessors. Each GLTFAccessor has two PoolVector, but the actual alloc count does not reach the limit thanks to COW. Later in the export process, each accessor needs to write to an empty PoolVector, so it triggers COW and reaches the 65535 limit.

All memory pool allocations are in use.

And crashes on further null pointer access.

timothyqiu avatar Aug 19 '21 03:08 timothyqiu

So is that something that needs to be worked around or can it be fixed?

stryker313 avatar Aug 19 '21 06:08 stryker313

I changed the COW number to be something above 65535, but need to find the exact place again and check on your input.

fire avatar Aug 19 '21 06:08 fire

I don't understand the semantics of this line.

diff --git a/core/pool_vector.h b/core/pool_vector.h
index 83e9fd243a..9d51150e20 100644
--- a/core/pool_vector.h
+++ b/core/pool_vector.h
@@ -38,6 +38,8 @@
 #include "core/safe_refcount.h"
 #include "core/ustring.h"
 
+#include <climits>
+
 struct MemoryPool {
        //avoid accessing these directly, must be public for template access
 
@@ -71,7 +73,7 @@ struct MemoryPool {
        static size_t total_memory;
        static size_t max_memory;
 
-       static void setup(uint32_t p_max_allocs = (1 << 16));
+       static void setup(uint32_t p_max_allocs = UINT_MAX);
        static void cleanup();
 };

Note:

I think last time the number I used experimentally was 1 << 20 instead of UINT_MAX. UINT_MAX crashes.

fire avatar Aug 19 '21 06:08 fire

For your character model and using the constant 1 << 20 I was able to export.

There are some other bugs in the gltf2 according to https://github.khronos.org/glTF-Validator/, but here's the output from godot engine.

MeshSmall.zip

image

image

fire avatar Aug 19 '21 07:08 fire

We can document this as a existing limitation of godot engine.

Numbers mentioned above: Exceeding 65535 GLTFAccessors

fire avatar Sep 23 '22 07:09 fire