guycalledfrank / bakery-issues

Bug tracker for Bakery
4 stars 0 forks source link

Generating LOD lightmap of terrain fails with the nullref #11

Open VergilUa opened 4 years ago

VergilUa commented 4 years ago

NullReferenceException: Object reference not set to an instance of an object ftRenderLightmap+<RenderLightmapFunc>d__252.MoveNext () (at Assets/Editor/x64/Bakery/scripts/ftRenderLightmap.cs:5614) ftRenderLightmap.RenderLightmapUpdate () (at Assets/Editor/x64/Bakery/scripts/ftRenderLightmap.cs:3743)

This is on Unity 2019.3.7f1 + HDRP 7.1.8. Bakery v.1.71, bake had following settings: image

Disabling "Terrain optimization" seems to solve the problem.

guycalledfrank commented 4 years ago

Hi, are you sure it's the full error message? Can't see anything specific on these lines. Is there also any error message starting with "Exception caught:"? It should have information on the deepest responsible line number. Also where was "LOD Lightmap" mentioned? Progressbar? I guess it has something to do with GI VRAM optimization + Terrain optimization combo then.

VergilUa commented 4 years ago

Hi, it's not. Stacktrace leads to a bunch of coroutine runing invokable functions (its the last useful line out there), so I've truncated it a bit.

Yes, LOD lightmap is mentioned in the progress bar. Baking gets stuck on that phase forever. It fails on the Debug.Log:

if (lmgroup2.containsTerrains)
                    {
                        Debug.Log("Running lmrebake (terrain) for " + lmgroup2.name + " (" + lmGroupLODResFlags[lmgroup2.id] + ")"); // here
                        int errCode2 = lmrRenderSimple(scenePath + "/" + lmgroup2.name + "_diffuse_HDR" + (compressedOutput ? ".lz4" : ".dds"),
                                            scenePath + "/" + lmgroup2.name + "_diffuse_HDR_LOD",
                                            lmgroup2.resolution/2, lmgroup2.resolution/2, lmGroupLODResFlags[lmgroup2.id]);
                        if (errCode2 != 0)
                        {
                            DebugLogError("Error rebaking lightmap (terrain) " + lmgroup2.name + ": " + ftErrorCodes.TranslateLMRebake(errCode2));
                            userCanceled = true;
                            yield break;
                        }
                    }

Perhaps wrap it in try / catch? Or check if that array's element exists?

guycalledfrank commented 4 years ago

Right... it's odd that it doesn't point to the actual problematic line number. LOD lightmaps are generated when GI VRAM optimization is on: https://geom.io/bakery/wiki/index.php?title=Manual#GI_VRAM_optimization

Which is on when estimated VRAM usage is higher than available. It's not well (enough) tested for the obvious reason of users not willing to provide any large scenes for debugging and this feature mostly only kicking in on large scenes.

Bakery works in a much more predictable fashion when this feature is off, but it will require you to reduce resolution (texels per unit/scale in lightmap) or get more VRAM.

It would help if you show me a full screenshot of all debug messages (not just errors) prior to the final error.

VergilUa commented 4 years ago

Here's a whole error:

NullReferenceException: Object reference not set to an instance of an object
  at ftRenderLightmap+<RenderLightmapFunc>d__252.MoveNext () [0x04bf5] in C:\Coding\D-Rifter\Assets\Editor\x64\Bakery\scripts\ftRenderLightmap.cs:5614 
  at ftRenderLightmap.RenderLightmapUpdate () [0x0004c] in C:\Coding\D-Rifter\Assets\Editor\x64\Bakery\scripts\ftRenderLightmap.cs:3743 
  at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <437ba245d8404784b9fbab9b439ac908>:0 
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00048] in <437ba245d8404784b9fbab9b439ac908>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000e7] in <437ba245d8404784b9fbab9b439ac908>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00008] in <437ba245d8404784b9fbab9b439ac908>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <437ba245d8404784b9fbab9b439ac908>:0 
  at UnityEditor.EditorApplication.Internal_CallUpdateFunctions () [0x00041] in <78f1ad0f25c84e3ca853e639f50d95f5>:0 

(Filename: Assets/Editor/x64/Bakery/scripts/ftRenderLightmap.cs Line: 5614)

image

image

There's lots of logs, so here's a log file from the bake start: log.txt