{"record":{"id":"dd778e1d265044d8","repo":"bevyengine/bevy","slug":"too-many-light-sources-in-the-scene-maximum-is-65","errorCode":null,"errorMessage":"Too many light sources in the scene, maximum is 65535.","messagePattern":"Too many light sources in the scene, maximum is 65535\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/bevy_solari/src/scene/binder.rs","lineNumber":261,"sourceCode":"\n        this_frame_entity_to_light_id.insert(entity, light_sources.get().len() as u32 - 1);\n        raytracing_scene_bindings\n            .previous_frame_light_entities\n            .push(entity);\n    }\n\n    for previous_frame_light_entity in previous_frame_light_entities {\n        let current_frame_index = this_frame_entity_to_light_id\n            .get(&previous_frame_light_entity)\n            .copied()\n            .unwrap_or(LIGHT_NOT_PRESENT_THIS_FRAME);\n        previous_frame_light_id_translations\n            .get_mut()\n            .push(current_frame_index);\n    }\n\n    if light_sources.get().len() > u16::MAX as usize {\n        panic!(\"Too many light sources in the scene, maximum is 65535.\");\n    }\n\n    materials.write_buffer(&render_device, &render_queue);\n    transforms.write_buffer(&render_device, &render_queue);\n    previous_frame_transforms.write_buffer(&render_device, &render_queue);\n    geometry_ids.write_buffer(&render_device, &render_queue);\n    material_ids.write_buffer(&render_device, &render_queue);\n    light_sources.write_buffer(&render_device, &render_queue);\n    directional_lights.write_buffer(&render_device, &render_queue);\n    previous_frame_light_id_translations.write_buffer(&render_device, &render_queue);\n\n    let mut command_encoder = render_device.create_command_encoder(&CommandEncoderDescriptor {\n        label: Some(\"tlas_build_command_encoder\"),\n    });\n    let time_span = diagnostics\n        .as_mut()\n        .map(|diagnostics| diagnostics.time_span(&mut command_encoder, \"tlas_build\"));\n    command_encoder.build_acceleration_structures(&[], [&tlas]);","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/bevyengine/bevy/blob/4805ca792c3e94eef07afd6fa9a2712f388c9a67/crates/bevy_solari/src/scene/binder.rs#L243-L279","documentation":"The Solari scene binder (scene/binder.rs:255-258) packs every light source — each emissive mesh light instance plus each directional light — into a GpuLightSource whose index must fit u16, so it panics when light_sources.len() exceeds 65535. The limit exists because light ids are addressed with 16 bits in the path tracer's buffers.","triggerScenarios":"Enabling Solari rendering in a scene whose combined count of emissive mesh light instances and directional lights exceeds 65,535; heavy instancing of meshes with emissive StandardMaterial.","commonSituations":"Procedurally scattering tens of thousands of emissive bulbs/strips; CAD or archviz imports where many parts carry emissive materials; switching a dense scene from the standard PBR pipeline to Solari path tracing.","solutions":["Reduce the number of emissive mesh lights — they dominate the count","Replace many small emissive objects with fewer merged/simplified emissive proxies","Keep directional light counts minimal","If the scene genuinely needs more, render it without Solari (standard mesh pipeline) instead of the path tracer"],"exampleFix":"// before — every bulb is its own emissive instance (100k light sources)\nfor i in 0..100_000 {\n    commands.spawn((bulb_mesh.clone(), emissive_material.clone()));\n}\n\n// after — one merged emissive strip provides the light, count stays under 65,535\ncommands.spawn((merged_strip_mesh, emissive_material));","handlingStrategy":"validation","validationCode":"// Before enabling Solari, count emissive mesh instances + directional lights\nfn assert_solari_light_budget(\n    emissive: Query<(), With<Handle<StandardMaterial>>>, // refine to emissive materials\n    directional: Query<(), With<DirectionalLight>>,\n) {\n    let count = emissive.iter().count() + directional.iter().count();\n    assert!(\n        count <= u16::MAX as usize,\n        \"Solari supports at most 65535 light sources, scene has {count}\"\n    );\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Track emissive instance counts during procedural generation and cap them below 65,535","Audit imported scenes for emissive materials before enabling the Solari path tracer","Merge small emissive meshes so instances (not triangles) stay the scarce resource you manage"],"tags":["bevy","solari","pathtracing","emissive","lighting","limits","panic"],"backgroundTag":"resource-limit-exceeded","analyzedSha":"4805ca792c3e94eef07afd6fa9a2712f388c9a67","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}