away3d的每个版本差异都特别大,之前使用3.6做了一个东西,在要交工时才发现render方法有内存泄漏,无耐之下又要用4.0重新做一遍,这一做就又是三天,真是差异太大了。
今天遇到一个很奇怪的问题: Error #3691: 超出此资源类型的资源限制。错误定位在 view.rendre()方法。以该错误的英文error #3691 resource limit for this resource type exceeded 在google中搜索(百度在这方面简直是垃圾!),有效解释如下:
“Which means that you are exceeding the texture resource limits in the Flash Player / Stage3D;”
Limits are described here:http://help.adobe.com/en_US/FlashPla...Context3D.html
Resource | Number allowed | Total memory |
---|---|---|
Vertex buffers |
4096 | 256 MB |
Index buffers |
4096 | 128 MB |
Programs |
4096 | 16 MB |
Textures |
4096 | 128 MB¹ |
Cube textures |
4096 | 256 MB |
又找到这样的解释:
“It seems the actual geometry of the Plane is never disposed, which prevents the buffers from being cleaned up”.
( 看起来像是实际的geometry没有销毁,仍然占用着缓存区。)
联想到我的应用,是反复执行删除mesh,添加mesh的操作,删除的代码如下:
/*清空scene中的内容*/ private function clearScene():void { while(this.tileGroup.numChildren>0) { var t:TileMesh=tileGroup.getChildAt(0) as TileMesh; tileGroup.removeChild(t); t.dispose(); //此处是对mesh的销毁,难道是没有真正销毁? t=null; } }
TileMesh是我继承自Mesh类实现的一个自己的mesh类,在从场景中删除时也执行了t.dispose() 这个销毁操作,有没有可能是这个销毁操作没有删除Mesh的Geometry呢?
修改代码如下:
/*清空scene中的内容*/ private function clearScene():void { while(this.tileGroup.numChildren>0) { var t:TileMesh=tileGroup.getChildAt(0) as TileMesh; tileGroup.removeChild(t); t.distroy(); //distroy是TileMesh中自己实现的一个方法,用于销毁geometry 和 material t=null; } }
distroy是TileMesh中自己实现的一个方法,用于销毁geometry 和 material,代码如下:
public function distroy():void { this.geometry.dispose(); this.material.dispose(); }
再次执行程序,运行正常,没有再出现之前的错误“ Error #3691: 超出此资源类型的资源限制”。