Skip to content

Commit cbb4de6

Browse files
authored
[GEN][ZH] Prevent dereferencing NULL pointer 'TheControlBar', 'window' in ControlBarCallback (#1148)
1 parent 19281c1 commit cbb4de6

File tree

2 files changed

+142
-156
lines changed

2 files changed

+142
-156
lines changed

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp

Lines changed: 71 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -501,121 +501,114 @@ extern void toggleReplayControls( void );
501501
//-------------------------------------------------------------------------------------------------
502502
void ShowControlBar( Bool immediate )
503503
{
504+
if (!TheWindowManager || !TheControlBar || !TheTacticalView)
505+
return;
506+
504507
showReplayControls();
505-
if(TheControlBar)
506-
TheControlBar->showSpecialPowerShortcut();
507-
if (TheWindowManager)
508+
509+
TheControlBar->showSpecialPowerShortcut();
510+
511+
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
512+
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
513+
514+
if (window)
508515
{
509-
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
510-
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
516+
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
517+
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
511518

512-
if (window)
513-
{
514-
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
515-
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
516-
if (TheControlBar->m_animateWindowManager && !immediate)
517-
{
518-
TheControlBar->m_animateWindowManager->reset();
519-
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, TRUE, 1000, 0);
520-
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
521-
TheControlBar->animateSpecialPowerShortcut(TRUE);
522-
}
523-
window->winHide(FALSE);
519+
if (TheControlBar->m_animateWindowManager && !immediate)
520+
{
521+
TheControlBar->m_animateWindowManager->reset();
522+
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, TRUE, 1000, 0);
523+
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
524+
TheControlBar->animateSpecialPowerShortcut(TRUE);
524525
}
525526

526-
}
527+
window->winHide(FALSE);
528+
}
527529

528530
// We want to get everything recalced since this is a major state change.
529-
if(TheControlBar)
530-
TheControlBar->markUIDirty();
531-
532-
}// void ShowControlBar(void)
531+
TheControlBar->markUIDirty();
532+
}
533533

534534
//-------------------------------------------------------------------------------------------------
535535
/** Force the control bar to be hidden */
536536
//-------------------------------------------------------------------------------------------------
537537
void HideControlBar( Bool immediate )
538538
{
539+
if (!TheWindowManager || !TheControlBar || !TheTacticalView)
540+
return;
541+
539542
hideReplayControls();
540-
if(TheControlBar)
541-
TheControlBar->hideSpecialPowerShortcut();
542-
if (TheWindowManager)
543-
{
544-
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
545-
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
546543

547-
if (window)
548-
{
544+
TheControlBar->hideSpecialPowerShortcut();
545+
546+
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
547+
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
548+
549+
if (window)
550+
{
549551
#ifdef SLIDE_LETTERBOX
550-
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
552+
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
551553
#else
552-
TheTacticalView->setHeight(TheDisplay->getHeight());
554+
TheTacticalView->setHeight(TheDisplay->getHeight());
553555
#endif
554-
}
555556
if (immediate)
556557
{
557558
window->winHide(TRUE);
558-
if(TheControlBar)
559-
TheControlBar->hideSpecialPowerShortcut();
560-
561-
}
562-
else
563-
{
564-
TheControlBar->m_animateWindowManager->reverseAnimateWindow();
565-
TheControlBar->animateSpecialPowerShortcut(FALSE);
566559
}
560+
}
567561

568-
//Always get rid of the purchase science screen!
569-
if( TheControlBar )
570-
{
571-
TheControlBar->hidePurchaseScience();
572-
}
573-
}
574-
}//void HideControlBar( void )
562+
if (TheControlBar->m_animateWindowManager && !immediate)
563+
{
564+
TheControlBar->m_animateWindowManager->reverseAnimateWindow();
565+
TheControlBar->animateSpecialPowerShortcut(FALSE);
566+
}
567+
568+
//Always get rid of the purchase science screen!
569+
TheControlBar->hidePurchaseScience();
570+
}
575571

576572
//-------------------------------------------------------------------------------------------------
577573
/** Toggle the control bar on or off */
578574
//-------------------------------------------------------------------------------------------------
579575
void ToggleControlBar( Bool immediate )
580576
{
577+
if (!TheWindowManager || !TheControlBar || !TheTacticalView)
578+
return;
579+
581580
toggleReplayControls();
582581

583-
if (TheWindowManager)
584-
{
585-
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
586-
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
582+
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
583+
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
587584

588-
if (window)
585+
if (window)
586+
{
587+
if (window->winIsHidden())
589588
{
590-
if (window->winIsHidden())
591-
{
592-
if(TheControlBar)
593-
TheControlBar->showSpecialPowerShortcut();
594-
595-
//now hidden, we're making it visible again so shrink viewport under the window
596-
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
597-
window->winHide(!window->winIsHidden());
598-
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
599-
if (TheControlBar->m_animateWindowManager && !immediate)
600-
{
601-
TheControlBar->m_animateWindowManager->reset();
602-
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, FALSE, 500, 0);
603-
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
604-
TheControlBar->animateSpecialPowerShortcut(TRUE);
605-
}
606-
}
607-
else
589+
TheControlBar->showSpecialPowerShortcut();
590+
591+
//now hidden, we're making it visible again so shrink viewport under the window
592+
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
593+
window->winHide(FALSE);
594+
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
595+
596+
if (TheControlBar->m_animateWindowManager && !immediate)
608597
{
609-
if(TheControlBar)
610-
TheControlBar->hideSpecialPowerShortcut();
611-
TheTacticalView->setHeight(TheDisplay->getHeight());
612-
window->winHide(!window->winIsHidden());
598+
TheControlBar->m_animateWindowManager->reset();
599+
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, FALSE, 500, 0);
600+
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
601+
TheControlBar->animateSpecialPowerShortcut(TRUE);
613602
}
614-
615603
}
616-
604+
else
605+
{
606+
TheControlBar->hideSpecialPowerShortcut();
607+
TheTacticalView->setHeight(TheDisplay->getHeight());
608+
window->winHide(TRUE);
609+
}
617610
}
618-
}// end void ToggleControlBar( void )
611+
}
619612

620613
//-------------------------------------------------------------------------------------------------
621614
/** Resize the control bar */

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp

Lines changed: 71 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -500,121 +500,114 @@ extern void toggleReplayControls( void );
500500
//-------------------------------------------------------------------------------------------------
501501
void ShowControlBar( Bool immediate )
502502
{
503+
if (!TheWindowManager || !TheControlBar || !TheTacticalView)
504+
return;
505+
503506
showReplayControls();
504-
if(TheControlBar)
505-
TheControlBar->showSpecialPowerShortcut();
506-
if (TheWindowManager)
507+
508+
TheControlBar->showSpecialPowerShortcut();
509+
510+
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
511+
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
512+
513+
if (window)
507514
{
508-
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
509-
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
515+
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
516+
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
510517

511-
if (window)
512-
{
513-
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
514-
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
515-
if (TheControlBar->m_animateWindowManager && !immediate)
516-
{
517-
TheControlBar->m_animateWindowManager->reset();
518-
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, TRUE, 1000, 0);
519-
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
520-
TheControlBar->animateSpecialPowerShortcut(TRUE);
521-
}
522-
window->winHide(FALSE);
518+
if (TheControlBar->m_animateWindowManager && !immediate)
519+
{
520+
TheControlBar->m_animateWindowManager->reset();
521+
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, TRUE, 1000, 0);
522+
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
523+
TheControlBar->animateSpecialPowerShortcut(TRUE);
523524
}
524525

525-
}
526+
window->winHide(FALSE);
527+
}
526528

527529
// We want to get everything recalced since this is a major state change.
528-
if(TheControlBar)
529-
TheControlBar->markUIDirty();
530-
531-
}// void ShowControlBar(void)
530+
TheControlBar->markUIDirty();
531+
}
532532

533533
//-------------------------------------------------------------------------------------------------
534534
/** Force the control bar to be hidden */
535535
//-------------------------------------------------------------------------------------------------
536536
void HideControlBar( Bool immediate )
537537
{
538+
if (!TheWindowManager || !TheControlBar || !TheTacticalView)
539+
return;
540+
538541
hideReplayControls();
539-
if(TheControlBar)
540-
TheControlBar->hideSpecialPowerShortcut();
541-
if (TheWindowManager)
542-
{
543-
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
544-
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
545542

546-
if (window)
547-
{
543+
TheControlBar->hideSpecialPowerShortcut();
544+
545+
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
546+
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
547+
548+
if (window)
549+
{
548550
#ifdef SLIDE_LETTERBOX
549-
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
551+
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
550552
#else
551-
TheTacticalView->setHeight(TheDisplay->getHeight());
553+
TheTacticalView->setHeight(TheDisplay->getHeight());
552554
#endif
553-
}
554555
if (immediate)
555556
{
556557
window->winHide(TRUE);
557-
if(TheControlBar)
558-
TheControlBar->hideSpecialPowerShortcut();
559-
560-
}
561-
else
562-
{
563-
TheControlBar->m_animateWindowManager->reverseAnimateWindow();
564-
TheControlBar->animateSpecialPowerShortcut(FALSE);
565558
}
559+
}
566560

567-
//Always get rid of the purchase science screen!
568-
if( TheControlBar )
569-
{
570-
TheControlBar->hidePurchaseScience();
571-
}
572-
}
573-
}//void HideControlBar( void )
561+
if (TheControlBar->m_animateWindowManager && !immediate)
562+
{
563+
TheControlBar->m_animateWindowManager->reverseAnimateWindow();
564+
TheControlBar->animateSpecialPowerShortcut(FALSE);
565+
}
566+
567+
//Always get rid of the purchase science screen!
568+
TheControlBar->hidePurchaseScience();
569+
}
574570

575571
//-------------------------------------------------------------------------------------------------
576572
/** Toggle the control bar on or off */
577573
//-------------------------------------------------------------------------------------------------
578574
void ToggleControlBar( Bool immediate )
579575
{
576+
if (!TheWindowManager || !TheControlBar || !TheTacticalView)
577+
return;
578+
580579
toggleReplayControls();
581580

582-
if (TheWindowManager)
583-
{
584-
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
585-
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
581+
Int id = (Int)TheNameKeyGenerator->nameToKey(AsciiString("ControlBar.wnd:ControlBarParent"));
582+
GameWindow *window = TheWindowManager->winGetWindowFromId(NULL, id);
586583

587-
if (window)
584+
if (window)
585+
{
586+
if (window->winIsHidden())
588587
{
589-
if (window->winIsHidden())
590-
{
591-
if(TheControlBar)
592-
TheControlBar->showSpecialPowerShortcut();
593-
594-
//now hidden, we're making it visible again so shrink viewport under the window
595-
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
596-
window->winHide(!window->winIsHidden());
597-
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
598-
if (TheControlBar->m_animateWindowManager && !immediate)
599-
{
600-
TheControlBar->m_animateWindowManager->reset();
601-
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, FALSE, 500, 0);
602-
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
603-
TheControlBar->animateSpecialPowerShortcut(TRUE);
604-
}
605-
}
606-
else
588+
TheControlBar->showSpecialPowerShortcut();
589+
590+
//now hidden, we're making it visible again so shrink viewport under the window
591+
TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
592+
window->winHide(FALSE);
593+
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
594+
595+
if (TheControlBar->m_animateWindowManager && !immediate)
607596
{
608-
if(TheControlBar)
609-
TheControlBar->hideSpecialPowerShortcut();
610-
TheTacticalView->setHeight(TheDisplay->getHeight());
611-
window->winHide(!window->winIsHidden());
597+
TheControlBar->m_animateWindowManager->reset();
598+
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, FALSE, 500, 0);
599+
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
600+
TheControlBar->animateSpecialPowerShortcut(TRUE);
612601
}
613-
614602
}
615-
603+
else
604+
{
605+
TheControlBar->hideSpecialPowerShortcut();
606+
TheTacticalView->setHeight(TheDisplay->getHeight());
607+
window->winHide(TRUE);
608+
}
616609
}
617-
}// end void ToggleControlBar( void )
610+
}
618611

619612
//-------------------------------------------------------------------------------------------------
620613
/** Resize the control bar */

0 commit comments

Comments
 (0)