Xanmia Posted February 25, 2014 Share Posted February 25, 2014 Not sure if this is object miss use or a bug.... When creating multiple dynamicTexures with drawText after around 3000 it crashes webGL, even with disposing of each object and texture right after it was created.However, you remove the drawText function call and it works fine. I have attached the full html file that I used to reproduce the error as well as provide a correction for work around. The below is the code in issue:function testFail(){total++;var background2 = BABYLON.Mesh.CreatePlane("COUNT", 20, scene);background2.material = new BABYLON.StandardMaterial("background", scene);background2.rotation.y = Math.PI;background2.rotation.x = Math.PI/2;background2.rotation.z = Math.PI*1.5; var backgroundTexture2 = new BABYLON.DynamicTexture("dynamic texture", 512, scene, true);background2.material.diffuseTexture = backgroundTexture2;backgroundTexture2.drawText("+5", null, 350, "bold 325px Segoe UI", "white", "#555555");backgroundTexture2.dispose();background2.dispose();backgroundTexture2=null;background2=null;} scene.registerBeforeRender(function() {StatusText.innerHTML = "total objects - " + total;//testWorks();testFail(); });Anyone else run into this??? I was going to put an issue in on github but wanted to validate... MemoryIssueWtext.html Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 25, 2014 Share Posted February 25, 2014 Hello, I was running your test and my chrome crashed at 9000 objects. It is clearly a memory crash : http://i.imgur.com/Mx8yyIl.pngSee the "System commit" graph. Any idea Delta ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 25, 2014 Share Posted February 25, 2014 Try to replace this line:backgroundTexture2.dispose() by this one:background2.material.dispose(); Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 25, 2014 Share Posted February 25, 2014 Everything is ok now. But does that means all materials should be disposed manually ? Quote Link to comment Share on other sites More sharing options...
Xanmia Posted February 25, 2014 Author Share Posted February 25, 2014 Yup, fixed on my end too, good question Temechon. I guess I assumed the background2.dispose() was doing that for me... Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 Everything is ok now. But does that means all materials should be disposed manually ? I guess the material could be shared so used by another mesh and that's why it's not disposed. Does it exist a property "references" on material such as for buffers? Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 Does it exist a property "references" on material such as for buffers? Quick check on GitHub. Looks like the answer is no. Quote Link to comment Share on other sites More sharing options...
Xanmia Posted February 26, 2014 Author Share Posted February 26, 2014 Not sure I am following on the property references on material. Do you have a code sample or are you referring to the references within Visual Studio? Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 26, 2014 Share Posted February 26, 2014 He is referring to an hypothetical attribute on the Material class in babylon js. This attribute is called 'references', and holds the number of mesh this material is linked to.With such an attribute, it would be easy to remove automatically all materials without any references (material.references === 0), as it is being done for meshes buffers and their clones. Gwenael checked in the source code of Babylon in Github, but this attribute does not exists, thus all material have to be removed manually. gwenael 1 Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 I couldn't have expressed myself better. Thanks Temechon. That was exactly what I wanted to say Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 Now Temechon you know how to do a pull request, it's all yours . Let me know if you don't do it. I may work on it tonight. Quote Link to comment Share on other sites More sharing options...
Temechon Posted February 26, 2014 Share Posted February 26, 2014 Sorry Gwenael, but I won't have the time to work on this tonight. Creating my first pull request was quite exhausting, and I have to rest now gwenael 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 26, 2014 Share Posted February 26, 2014 materials do not track references for now because :They can be shared between meshes (this is a good thing for performance)You can have a material ready to be used but not affected to a mesh (and you do not want to dispose it:))Disposing texture must not dispose materials (but the opposite is true) Quote Link to comment Share on other sites More sharing options...
gwenael Posted February 26, 2014 Share Posted February 26, 2014 May I suggest to add an optional paramater?BABYLON.Material = function (name, scene, notShared) { this.name = name; this.id = name; this._scene = scene; scene.materials.push(this); this._canBeShared = !notShared;};Thus, by default, a material can be shared (current behavior) but you can specify while creating it that you don't want to share it. When a mesh is disposed, we check if its material can be shared. If it can be disposed then we dispose it during disposing the mesh. Maybe this change wouldn't be useful though... Xanmia 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 27, 2014 Share Posted February 27, 2014 Not sure though material are shared by essence from my point of view Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.