File tree Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Expand file tree Collapse file tree 3 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ Object.assign(pc, function () {
61
61
62
62
this . node = node ; // The node that defines the transform of the mesh instance
63
63
this . _mesh = mesh ; // The mesh that this instance renders
64
- mesh . _refCount ++ ;
64
+ mesh . incReference ( ) ;
65
65
this . material = material ; // The material with which to render this instance
66
66
67
67
this . _shaderDefs = pc . MASK_DYNAMIC << 16 ; // 2 byte toggles, 2 bytes light mask; Default value is no toggles and mask = pc.MASK_DYNAMIC
@@ -118,9 +118,9 @@ Object.assign(pc, function () {
118
118
return this . _mesh ;
119
119
} ,
120
120
set : function ( mesh ) {
121
- if ( this . _mesh ) this . _mesh . _refCount -- ;
121
+ if ( this . _mesh ) this . _mesh . decReference ( ) ;
122
122
this . _mesh = mesh ;
123
- if ( mesh ) mesh . _refCount ++ ;
123
+ if ( mesh ) mesh . incReference ( ) ;
124
124
}
125
125
} ) ;
126
126
Original file line number Diff line number Diff line change @@ -177,7 +177,22 @@ Object.assign(pc, function () {
177
177
}
178
178
} ) ;
179
179
180
+ Object . defineProperty ( Mesh . prototype , 'refCount' , {
181
+ get : function ( ) {
182
+ return this . _refCount ;
183
+ }
184
+ } ) ;
185
+
180
186
Object . assign ( Mesh . prototype , {
187
+
188
+ incReference : function ( ) {
189
+ this . _refCount ++ ;
190
+ } ,
191
+
192
+ decReference : function ( ) {
193
+ this . _refCount -- ;
194
+ } ,
195
+
181
196
/**
182
197
* @function
183
198
* @name pc.Mesh#destroy
Original file line number Diff line number Diff line change @@ -171,12 +171,11 @@ Object.assign(pc, function () {
171
171
172
172
mesh = meshInstance . mesh ;
173
173
if ( mesh ) {
174
- mesh . _refCount -- ;
175
- if ( mesh . _refCount < 1 ) {
174
+ meshInstance . mesh = null ; // this calls decReference on mesh
175
+ if ( mesh . refCount < 1 ) {
176
176
mesh . destroy ( ) ;
177
177
}
178
178
}
179
- meshInstance . mesh = null ;
180
179
181
180
skin = meshInstance . skinInstance ;
182
181
if ( skin ) {
You can’t perform that action at this time.
0 commit comments