@@ -72,29 +72,35 @@ <h3>Event Log:</h3>
7272 log ( 'Creating ArtoolkitPlugin instance (dist build)…' ) ;
7373 plugin = new ArtoolkitPlugin ( {
7474 worker : true ,
75- cameraParametersUrl : '/examples/simple-marker/data/camera_para.dat' ,
76- // minConfidence: 0.6,
75+ cameraParametersUrl : '/examples/simple-marker/data/camera_para.dat'
7776 } ) ;
78- await plugin . init ( core ) ;
79- await plugin . enable ( ) ;
8077
78+ // Register listeners BEFORE enable to avoid missing early 'ready'
8179 eventBus . on ( 'ar:workerReady' , ( ) => {
8280 log ( 'Worker ready' ) ;
8381 setStatus ( 'Worker ready. Start camera and then load marker.' , 'success' ) ;
8482 loadMarkerBtn . disabled = false ;
8583 } ) ;
86-
8784 eventBus . on ( 'ar:workerError' , e => {
8885 log ( `workerError: ${ JSON . stringify ( e ) } ` ) ;
8986 setStatus ( 'Worker error (see console)' , 'error' ) ;
9087 } ) ;
91-
9288 eventBus . on ( 'ar:getMarker' , ( e ) => console . log ( '[example] ar:getMarker' , e ) ) ;
9389 eventBus . on ( 'ar:markerFound' , d => log ( `markerFound: ${ JSON . stringify ( d ) } ` ) ) ;
9490 eventBus . on ( 'ar:markerUpdated' , d => log ( `markerUpdated: ${ JSON . stringify ( d ) } ` ) ) ;
9591 eventBus . on ( 'ar:markerLost' , d => log ( `markerLost: ${ JSON . stringify ( d ) } ` ) ) ;
9692
97- setStatus ( 'Plugin initialized. Waiting for worker…' , 'normal' ) ;
93+ await plugin . init ( core ) ;
94+ await plugin . enable ( ) ;
95+
96+ // Fallback: if worker became ready during enable, honor it
97+ if ( plugin . workerReady ) {
98+ log ( 'Worker was already ready (post-enable).' ) ;
99+ setStatus ( 'Worker ready. Start camera and then load marker.' , 'success' ) ;
100+ loadMarkerBtn . disabled = false ;
101+ } else {
102+ setStatus ( 'Plugin initialized. Waiting for worker…' , 'normal' ) ;
103+ }
98104 } catch ( err ) {
99105 log ( 'Init error: ' + ( err && err . message ? err . message : err ) ) ;
100106 setStatus ( 'Initialization error' , 'error' ) ;
0 commit comments