Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Gilles Boulard 0

Pages: [1]
1
2.5.2 fixes the problem for us :)

2

fyi @keston (and others)

we did manage to pass-through the problem and avoid memory stacking at runtime :

- put substances in assetbundles (so it can be reloaded later on)
- load assetbundles wisth substances
- render textures with randomseed
- CopyTextures
- once a substance archive is no longer used, call
Code: [Select]
Substance.Game.Substance.Unload(graph.substance.assetpath)
to free memory , warning don't reuse any graph from taht archive anymore
- do not store any ref to the substancegraph, only keep the copied textures and materials

-if you need to regenerate textures later on :
- reload the assetbundle to restore the substance archive
-redo render+copy process

still, it would be nice to be able to reload the graph without having to reload the entire assets.
and, when loading the unity project for the first time, we still have to do it by batch of 4 or 5 substance files and closing unity in between to free memory. so a patch is still welcomed (but we are not stuck anymore :) )


3
sample send to @keston (mp/mail)

4
I Will try to build a sample app (and ask if i can send those fileto my hierarchy ^^)

further investigations :
i can generate endlessly on 1 archive and it will be just fine.
as soon as i add different SubstanceGraph, it takes like 2Go in memory per graph.
I wouldn't mind if this was temporary, but this memory is never freed.

so the problem could be summarize in one question :
what is the way to completely clear the memory that is used by an archive once textures have been generated ?

5
Ok, so i idg a bit more in the problem

this is apparently coming from the QueueForRender() +RenderAsync()

i tried to copy 1000 times the 3 same 512² textures, and got like 2Go more memory.
then i launch 50 times the same QueueForRender() +RenderAsync() (with a random seed) WITHOUT storing the resulting textures and the memory got up 2Go at each generation!

note: when exiting playmode in unity, the memory stays the same in edit mode, it needs to get "played" again to reset back to 0.

So :
-  what garbage does he process keep in memory ?
- can it come from our archive ? what could it be ?
- and finally : how can i clean all this garbage once the texture has been generated ?

6
still struggling through memory problems....

if i used the already generated default material and textures in the archive, memory is totally fine.
as soon as i will use a QueueForRender, Render(A)Sync memory is going up drastically, like 1Go memory per substance...

where does all that memory comes from ? is it only the generated textures? deos the graph have some sort of garbage data that i can clean up  ?

7
damn you were right the RenderSync is not sync at all -_-...
gonna go your way with ResetGeneratedTextures(); and testing GetGeneratedTextures().Count

 :-X :-X :-X

8
when using RenderAsync, i think you need to use
Code: [Select]
Substance.IsJobCompleted(uint)..but when i tried it never get out of the loop...

and as you said api doc is ... mostly void

RenderSync does bloc though.

By chance, do you have your code snippet where you copy the material and generated textures ?
can't find anything clean .

i got 3 textures as output, but do not know how to assign them to the correct textureid in the new material.
i would loike to make it generic enough so that i don't have to seaarch if the texture name contains "diffuse" or "metallic" to assign into the corresponding mat.

something like that (but this doesn't work ^^)
Code: [Select]
public void CopyTextures()
{
List<int> texturesIds = new List<int>();
Graph.material.GetTexturePropertyNameIDs(texturesIds);

//var orignalTextures = Graph.GetGeneratedTextures();
_textures = new List<Texture2D>();
for (int i = 0; i < texturesIds.Count; ++i)
{
Texture2D t = Graph.material.GetTexture(i) as Texture2D;
if (t != null)
{
Texture2D newTex = new Texture2D(t.width, t.height, t.format, t.mipmapCount > 0);
Graphics.CopyTexture(t, newTex);
_textures.Add(newTex);
_mat.SetTexture(texturesIds[i], newTex);

}
//Texture2D t = orignalTextures[i];
}
}

9
Thanks mate!

yes we are going to do just that, generate textures and copy them.
just didn't managed to find correct script to assign the 3 textures to correct material indexes yet.

and be sure to have all substanceGraph cleaned up after that.
Do you use .Substance.Free() ?:

Code: [Select]
var list = Substance.Game.Substance.ListLoadedAssetPaths();
foreach (var sub in list)
{
Substance.Game.Substance.Free(sub);
}

10
Hello,

substance api is not really helpful : not up to date (api refers to 2.2 when plugin is 2.5), and almost no info on public functions, not even a comment in the code above functions.

we are using substance to generate lots of random different textures from like maybe 50+ SubstanceGraph.
we would like to have a random texture each time we launch the app or on demand during a loading for example. but we don't need to make the txture chage after it, so apparently we don't need to keep the SubstanceGraph.

Currently the "Total System Memory Usage" is sky rocketting (each substance graph is generating 3 1024² textures : albedo, normal, metallic).

What would be the script to keep only the material and textures once the generation has been done. Would it be enough to solve our memory problem ?

we've tried the Substance.Free(string assetPath) after we copied the material, but textures seems to be destroyed.
maybe keep a ref on textures with GetGeneratedTextures ?

any help aprreciated

11
and finally .. Unity crashes (App Version: Unity 2019.3.6f1_5c3fb0a11183):

Code: [Select]
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) object.wrapper_native_00007FFD348450C0 (intptr) [0x00009] in <437ba245d8404784b9fbab9b439ac908>:0
  at Substance.Platform.NativeFunctions.cppGetPreset (intptr) [0x0003d] in D:\Git\projectname\Unity\Assets\Allegorithmic\Plugins\Substance.Platform\NativeFunctions.cs:377
  at Substance.Game.SubstanceGraph.get_preset () [0x00006] in <686b229c4bb54a199af4ea1b7d9b3fc4>:0
  at Substance.Game.SubstanceGraph.DuplicateInstance (Substance.Game.SubstanceGraph,string) [0x00089] in <686b229c4bb54a199af4ea1b7d9b3fc4>:0
  at Substance.Game.SubstanceGraph.Duplicate (Substance.Game.SubstanceGraph,string) [0x00002] in <686b229c4bb54a199af4ea1b7d9b3fc4>:0
  at Substance.Game.SubstanceGraph.Duplicate (Substance.Game.SubstanceGraph) [0x00007] in <686b229c4bb54a199af4ea1b7d9b3fc4>:0
  at Substance.Game.SubstanceGraph.Duplicate () [0x00002] in <686b229c4bb54a199af4ea1b7d9b3fc4>:0

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Crash!!!

========== OUTPUTTING STACK TRACE ==================

0x00007FFD3486074D (Substance.Engine) cppShutdownSubstance
0x00007FFD3484EEAB (Substance.Engine) cppShutdownSubstance
0x0000019F6BFCEC08 (Mono JIT Code) (wrapper managed-to-native) object:wrapper_native_00007FFD348450C0 (intptr)
0x0000019F6BFCEA83 (Mono JIT Code) [D:\Git\projectname\Unity\Assets\Allegorithmic\Plugins\Substance.Platform\NativeFunctions.cs:377] Substance.Platform.NativeFunctions:cppGetPreset (intptr)
0x0000019F6BFCE61B (Mono JIT Code) Substance.Game.SubstanceGraph:get_preset ()
0x0000019F6BFCBF7B (Mono JIT Code) Substance.Game.SubstanceGraph:DuplicateInstance (Substance.Game.SubstanceGraph,string)
0x0000019F6BFC9303 (Mono JIT Code) Substance.Game.SubstanceGraph:Duplicate (Substance.Game.SubstanceGraph,string)
0x0000019F6BFC90A3 (Mono JIT Code) Substance.Game.SubstanceGraph:Duplicate (Substance.Game.SubstanceGraph)
0x0000019F6BFC8F83 (Mono JIT Code) Substance.Game.SubstanceGraph:Duplicate ()
...
<GenerateRandomMats>d__16:MoveNext ()
0x0000019F666DCB31 (Mono JIT Code) UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
0x0000019F666DCD20 (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_object_intptr (object,intptr,intptr,intptr)
0x00007FFCC30DCBB0 (mono-2.0-bdwgc) [c:\build\output\unity-technologies\mono\mono\mini\mini-runtime.c:2809] mono_jit_runtime_invoke
0x00007FFCC3062122 (mono-2.0-bdwgc) [c:\build\output\unity-technologies\mono\mono\metadata\object.c:2921] do_runtime_invoke
0x00007FFCC306B11F (mono-2.0-bdwgc) [c:\build\output\unity-technologies\mono\mono\metadata\object.c:2968] mono_runtime_invoke
0x00007FF793B05D1E (Unity) scripting_method_invoke
0x00007FF793AFFA6D (Unity) ScriptingInvocation::Invoke
0x00007FF793AC1FDF (Unity) Coroutine::Run
0x00007FF793AD4BCC (Unity) MonoBehaviour::TryCreateAndRunCoroutine
0x00007FF793AC03AA (Unity) Coroutine::HandleIEnumerableCurrentReturnValue
0x00007FF793AC1D1F (Unity) Coroutine::ProcessCoroutineCurrent
0x00007FF793AC2113 (Unity) Coroutine::Run
0x00007FF793ABF54C (Unity) Coroutine::ContinueCoroutine
0x00007FF79317EA18 (Unity) DelayedCallManager::Update
0x00007FF7935AD15F (Unity) `InitPlayerLoopCallbacks'::`2'::UpdateScriptRunDelayedDynamicFrameRateRegistrator::Forward
0x00007FF7935963D8 (Unity) ExecutePlayerLoop
0x00007FF7935964AD (Unity) ExecutePlayerLoop
0x00007FF79359B6F4 (Unity) PlayerLoop
0x00007FF7919A799B (Unity) PlayerLoopController::UpdateScene
0x00007FF7919A58D8 (Unity) Application::TickTimer
0x00007FF7922ECF80 (Unity) MainMessageLoop
0x00007FF7922F6D1A (Unity) WinMain
0x00007FF7952895E2 (Unity) __scrt_common_main_seh
0x00007FFD48877BD4 (KERNEL32) BaseThreadInitThunk
0x00007FFD48B4CED1 (ntdll) RtlUserThreadStart

========== END OF STACKTRACE ===========


12

we get this error very often but not always...
this can happen in editor or at runtime. when in unity editor we have to quit and relaunch unity.

Code: [Select]
NullReferenceException: Object reference not set to an instance of an object.
  at Substance.Game.SubstanceGraph.OnEnable () [0x00000] in <00000000000000000000000000000000>:0
  at UnityEngine.ScriptableObject.CreateInstance[T] () [0x00000] in <00000000000000000000000000000000>:0
  at Substance.Game.SubstanceGraph.CreateGraphInstance (Substance.Game.Substance parent, System.UInt32 descIndex, System.UInt32 instanceIndex, System.String packageURL, System.String graphLabel, System.String prototypeName, System.String description, System.String category, System.String keywords, System.String author, System.String authorURL, System.String userTag) [0x00000] in <00000000000000000000000000000000>:0
  at Substance.Game.SubstanceGraph.DuplicateInstance (Substance.Game.SubstanceGraph graph, System.String pNewGraphName) [0x00000] in <00000000000000000000000000000000>:0
  at Substance.Game.SubstanceGraph.Duplicate (Substance.Game.SubstanceGraph graph1, System.String pNewGraphName) [0x00000] in <00000000000000000000000000000000>:0

sometimes this error comes instead:
Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
Substance.Game.SubstanceGraph.GetUniqueGraphName (Substance.Game.Substance substance, System.String prototypeName) (at <686b229c4bb54a199af4ea1b7d9b3fc4>:0)
Substance.Game.SubstanceGraph.DuplicateInstance (Substance.Game.SubstanceGraph graph, System.String pNewGraphName) (at <686b229c4bb54a199af4ea1b7d9b3fc4>:0)
Substance.Game.SubstanceGraph.Duplicate (Substance.Game.SubstanceGraph graph1, System.String pNewGraphName) (at <686b229c4bb54a199af4ea1b7d9b3fc4>:0)
Substance.Game.SubstanceGraph.Duplicate (Substance.Game.SubstanceGraph graph1) (at <686b229c4bb54a199af4ea1b7d9b3fc4>:0)
Substance.Game.SubstanceGraph.Duplicate () (at <686b229c4bb54a199af4ea1b7d9b3fc4>:0)

we don't do anything special.
loading the substance graph from an assetbundle (at runtime) or as a referenced asset (in editor)
trying to duplicate it to change the randomseed and use the new material.

this is done in a loop with async rendering in parallel, could it be a problem (both rendering and duplicate - maybe some concurrent access in threads?)
Code: [Select]
for (int i = 0; i < nb; i++)
{

// clone substance graph
sgClone = substanceRef.Duplicate();

sgClone.SetInputFloat("$randomseed", Random.Range(0, 1 << 8));
// render substance graph
sgClone.QueueForRender();
sgClone.RenderAsync();
_RandomizeSubstancesData.Add(new SubstanceData(new Material(sgClone.material), refid));
}

13
using Unity 2019.3.6f1

just installed the substance unity plugin, without any substance file yet (starting project ;) )

14
hi @keston ,
any info on this bug ?

 still occurs with :
Version 2.4.5(current)
Released: Apr 6, 2020

it does have an impact for us, as we also use the PlayModeStateChanged event from Unity and because substance is raising an exception, our code does not get called :p

Pages: [1]