@@ -499,9 +499,21 @@ bool GlobalIlluminationVct::eventFilter(QObject *_obj, QEvent *_event)
499
499
}
500
500
else if (this ->dataPtr ->debugVisualizationDirty )
501
501
{
502
- this ->dataPtr ->gi ->SetDebugVisualization (
502
+ if (this ->dataPtr ->enabled && this ->dataPtr ->gi ->Enabled ())
503
+ {
504
+ this ->dataPtr ->gi ->SetDebugVisualization (
503
505
static_cast <rendering::GlobalIlluminationVct::DebugVisualizationMode>(
504
- this ->dataPtr ->debugVisMode ));
506
+ this ->dataPtr ->debugVisMode ));
507
+ }
508
+ else
509
+ {
510
+ gzerr << " Trying to set debug visualization mode while GI is "
511
+ << " disabled. Please enable GI first."
512
+ << std::endl;
513
+ // Always set to none when disabled to avoid crash
514
+ this ->dataPtr ->gi ->SetDebugVisualization (
515
+ rendering::GlobalIlluminationVct::DVM_None);
516
+ }
505
517
this ->dataPtr ->debugVisualizationDirty = false ;
506
518
}
507
519
}
@@ -549,9 +561,23 @@ void GlobalIlluminationVct::UpdateOctantCount(int _axis, uint32_t _count)
549
561
// ////////////////////////////////////////////////
550
562
void GlobalIlluminationVct::SetEnabled (const bool _enabled)
551
563
{
552
- std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
553
- this ->dataPtr ->enabled = _enabled;
554
- this ->dataPtr ->visualDirty = true ;
564
+ bool needEmitDebugVisChanged = false ;
565
+ {
566
+ std::lock_guard<std::mutex> lock (this ->dataPtr ->serviceMutex );
567
+ if (this ->dataPtr ->enabled && !_enabled)
568
+ {
569
+ // When disabling GI, force debugVisMode to None for safety
570
+ this ->dataPtr ->debugVisMode = rendering::GlobalIlluminationVct::DVM_None;
571
+ this ->dataPtr ->debugVisualizationDirty = true ;
572
+ needEmitDebugVisChanged = true ;
573
+ }
574
+ this ->dataPtr ->enabled = _enabled;
575
+ this ->dataPtr ->visualDirty = true ;
576
+ }
577
+ if (needEmitDebugVisChanged)
578
+ {
579
+ this ->DebugVisualizationModeChanged ();
580
+ }
555
581
}
556
582
557
583
// ////////////////////////////////////////////////
0 commit comments