* Updates the canvas with new frame data from FastLED * @param {FrameData | (Array & {screenMap?: ScreenMapData})} frameData - Frame data with pixel information and screen mapping
(frameData)
| 460 | * @param {FrameData | (Array & {screenMap?: ScreenMapData})} frameData - Frame data with pixel information and screen mapping |
| 461 | */ |
| 462 | function updateCanvas(frameData) { |
| 463 | // we are going to add the screenMap to the graphicsManager |
| 464 | if (frameData.screenMap === undefined) { |
| 465 | console.warn('Screen map not found in frame data, skipping canvas update'); |
| 466 | return; |
| 467 | } |
| 468 | if (!graphicsManager) { |
| 469 | // Ensure graphicsArgs has required properties |
| 470 | const currentGraphicsArgs = { |
| 471 | canvasId: canvasId || 'canvas', |
| 472 | threeJsModules: graphicsArgs.threeJsModules || null, |
| 473 | ...graphicsArgs |
| 474 | }; |
| 475 | |
| 476 | // Try to create graphics manager - default to ThreeJS (gfx=1) if not specified |
| 477 | try { |
| 478 | if (FORCE_FAST_RENDERER) { |
| 479 | console.log('Creating Fast GraphicsManager with canvas ID (gfx=0)', canvasId); |
| 480 | graphicsManager = new GraphicsManager(currentGraphicsArgs); |
| 481 | } else { |
| 482 | // Default to ThreeJS renderer (gfx=1) if no parameter specified |
| 483 | const explicitlyRequested = FORCE_THREEJS_RENDERER ? 'gfx=1' : 'default (gfx=1)'; |
| 484 | console.log(`Creating Beautiful GraphicsManager with canvas ID (${explicitlyRequested})`, canvasId); |
| 485 | graphicsManager = new GraphicsManagerThreeJS(currentGraphicsArgs); |
| 486 | } |
| 487 | } catch (error) { |
| 488 | console.error('Failed to create graphics manager:', error); |
| 489 | |
| 490 | const errorDisplay = document.getElementById('error-display'); |
| 491 | if (errorDisplay) { |
| 492 | errorDisplay.textContent = `Graphics initialization failed: ${error.message}`; |
| 493 | errorDisplay.style.color = '#ff6b6b'; // Red error color |
| 494 | } |
| 495 | return; // Exit early on failure |
| 496 | } |
| 497 | |
| 498 | // Expose graphics manager globally for video recorder initialization |
| 499 | window.graphicsManager = graphicsManager; |
| 500 | |
| 501 | uiCanvasChanged = false; |
| 502 | } |
| 503 | |
| 504 | if (uiCanvasChanged) { |
| 505 | uiCanvasChanged = false; |
| 506 | try { |
| 507 | graphicsManager.reset(); |
| 508 | } catch (resetError) { |
| 509 | console.error('Graphics manager reset failed:', resetError); |
| 510 | // Try to recreate the graphics manager |
| 511 | graphicsManager = null; |
| 512 | updateCanvas(frameData); // Recursive call to recreate |
| 513 | return; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | try { |
| 518 | graphicsManager.updateCanvas(frameData); |
| 519 | } catch (updateError) { |
nothing calls this directly
no test coverage detected