File tree Expand file tree Collapse file tree 3 files changed +50
-4
lines changed
Expand file tree Collapse file tree 3 files changed +50
-4
lines changed Original file line number Diff line number Diff line change 22 * @import { GraphicsDevice } from './graphics-device.js'
33 * @import { StorageBuffer } from './storage-buffer.js'
44 * @import { Texture } from './texture.js'
5+ * @import { EventHandle } from '../../core/event-handle.js'
56 */
67
78/**
1516 * @ignore
1617 */
1718class UploadStream {
19+ /**
20+ * Event handle for device lost event.
21+ *
22+ * @type {EventHandle|null }
23+ * @protected
24+ */
25+ _deviceLostEvent = null ;
26+
1827 /**
1928 * Create a new UploadStream instance.
2029 *
@@ -29,6 +38,21 @@ class UploadStream {
2938
3039 // Create platform-specific implementation
3140 this . impl = device . createUploadStreamImpl ( this ) ;
41+
42+ // Register device lost handler
43+ this . _deviceLostEvent = this . device . on ( 'devicelost' , this . _onDeviceLost , this ) ;
44+ }
45+
46+ /**
47+ * Destroy the upload stream and clean up all pooled resources.
48+ */
49+ destroy ( ) {
50+ // Remove event listener
51+ this . _deviceLostEvent ?. off ( ) ;
52+ this . _deviceLostEvent = null ;
53+
54+ this . impl ?. destroy ( ) ;
55+ this . impl = null ;
3256 }
3357
3458 /**
@@ -53,11 +77,12 @@ class UploadStream {
5377 }
5478
5579 /**
56- * Destroy the upload stream and clean up all pooled resources.
80+ * Handles device lost event. Override in platform implementations.
81+ *
82+ * @private
5783 */
58- destroy ( ) {
59- this . impl ?. destroy ( ) ;
60- this . impl = null ;
84+ _onDeviceLost ( ) {
85+ this . impl ?. _onDeviceLost ?. ( ) ;
6186 }
6287}
6388
Original file line number Diff line number Diff line change @@ -44,6 +44,17 @@ class WebglUploadStream {
4444 } ) ;
4545 }
4646
47+ /**
48+ * Handles device lost event by clearing all PBO and sync object arrays.
49+ *
50+ * @protected
51+ */
52+ _onDeviceLost ( ) {
53+ // Clear arrays without trying to delete objects (context is already lost)
54+ this . availablePBOs . length = 0 ;
55+ this . pendingPBOs . length = 0 ;
56+ }
57+
4758 /**
4859 * Update PBOs: poll completed ones and remove undersized buffers.
4960 *
Original file line number Diff line number Diff line change @@ -39,6 +39,16 @@ class WebgpuUploadStream {
3939 this . useSingleBuffer = uploadStream . useSingleBuffer ;
4040 }
4141
42+ /**
43+ * Handles device lost event.
44+ * TODO: Implement proper WebGPU device lost handling if needed.
45+ *
46+ * @protected
47+ */
48+ _onDeviceLost ( ) {
49+ // WebGPU device lost handling not yet implemented
50+ }
51+
4252 destroy ( ) {
4353 this . _destroyed = true ;
4454 this . availableStagingBuffers . forEach ( buffer => buffer . destroy ( ) ) ;
You can’t perform that action at this time.
0 commit comments