1- import { Texture2D } from "../../cocos/asset/assets/texture-2d" ;
2- import { Details } from "../../cocos/serialization/deserialize" ;
1+ import { ImageAsset } from '../../cocos/asset/assets/image-asset' ;
2+ import { Texture2D } from '../../cocos/asset/assets/texture-2d' ;
3+ import { dependMap } from '../../cocos/asset/asset-manager/depend-maps' ;
4+ import dependUtil from '../../cocos/asset/asset-manager/depend-util' ;
5+ import { setProperties } from '../../cocos/asset/asset-manager/utilities' ;
6+ import { macro } from '../../cocos/core' ;
37
4- // issue: https://github.com/cocos/cocos-engine/issues/16693
5- test ( 'Texture2D serialize' , function ( ) {
6- const texture = new Texture2D ( ) ;
7- texture . _mipmaps = [ { _uuid : '09f4f3e7-268b-478c-a7af-bbdf574ec3c6@6c48a' } ] ;
8- const ctxForExporting = {
9- _depends : [ ] as string [ ] ,
10- dependsOn ( propName : string , uuid : string ) {
11- this . _depends . push ( propName , uuid ) ;
12- } ,
13- _compressUuid : this . mustCompresseUuid ,
14- } ;
15- texture . _serialize ( ctxForExporting ) ;
16- expect ( ctxForExporting . _depends ) . toEqual ( [ '_textureSource' , '09f4f3e7-268b-478c-a7af-bbdf574ec3c6@6c48a' ] ) ;
8+ const textureUuid = 'f41e5c8f-0e9a-4c38-bb1d-texture2d' ;
9+
10+ afterEach ( ( ) => {
11+ dependUtil . remove ( textureUuid ) ;
1712} ) ;
1813
19- test ( 'Texture2D deserialize' , function ( ) {
20- const data = { base : '2,2,2,2,0,0' , mipmaps : [ '09f4f3e7-268b-478c-a7af-bbdf574ec3c6' ] } ;
21- const result = new Details ( ) ;
22- result . init ( ) ;
23- const handle = { result } ;
24- const texture = new Texture2D ( ) ;
25- texture . _deserialize ( data , handle ) ;
26- expect ( handle . result . uuidList ) . toEqual ( [ '09f4f3e7-268b-478c-a7af-bbdf574ec3c6' ] ) ;
27- } ) ;
14+ test ( 'releases every Texture2D dependency edge for an uploaded image' , ( ) => {
15+ const cleanupImageCache = macro . CLEANUP_IMAGE_CACHE ;
16+ macro . CLEANUP_IMAGE_CACHE = true ;
17+
18+ try {
19+ const texture = new Texture2D ( ) ;
20+ texture . _uuid = textureUuid ;
21+ const image = new ImageAsset ( {
22+ _data : new Uint8Array ( 4 ) ,
23+ width : 1 ,
24+ height : 1 ,
25+ } ) ;
26+ image . _uuid = '6d35c119-b763-4295-96e7-image' ;
27+ const deps = [
28+ { uuid : image . _uuid , owner : texture , prop : '_textureSource' } ,
29+ { uuid : image . _uuid , owner : texture . _mipmaps , prop : '0' } ,
30+ ] ;
31+ const assetsMap = { [ `${ image . _uuid } @import` ] : image } ;
32+
33+ dependMap . set ( texture , deps ) ;
34+ dependUtil . _depends . add ( textureUuid , { deps : deps . map ( ( dep ) => dep . uuid ) } ) ;
35+ setProperties ( textureUuid , texture , assetsMap ) ;
36+ expect ( image . refCount ) . toBe ( 2 ) ;
37+
38+ texture . onLoaded ( ) ;
39+
40+ expect ( image . refCount ) . toBe ( 0 ) ;
41+ expect ( dependUtil . getDeps ( textureUuid ) ) . toEqual ( [ ] ) ;
42+ } finally {
43+ macro . CLEANUP_IMAGE_CACHE = cleanupImageCache ;
44+ }
45+ } ) ;
0 commit comments