@@ -620,51 +620,66 @@ int32_t loadSettings(int32_t memoryCardSlot)
620
620
FrameAdvance.FrameAdvanceButtonCombos .PauseButtonCombo = ButtonCombo;
621
621
}
622
622
623
+ // Get the hit check visualization data
624
+ HitCheck.Settings .DrawHits = Settings->HitCheckSettings .DrawHits ;
625
+ HitCheck.Settings .DrawMisses = Settings->HitCheckSettings .DrawMisses ;
626
+
627
+ // Only get the colors if their alphas are not 0
628
+ uint32_t HitsColor = Settings->HitCheckSettings .HitsColor ;
629
+ if ((HitsColor & 0xFF ) != 0 )
630
+ {
631
+ HitCheck.Settings .HitsColor = HitsColor;
632
+ }
633
+
634
+ uint32_t MissesColor = Settings->HitCheckSettings .MissesColor ;
635
+ if ((MissesColor & 0xFF ) != 0 )
636
+ {
637
+ HitCheck.Settings .MissesColor = MissesColor;
638
+ }
639
+
623
640
// Get the custom states
641
+ // If there were any previously, then delete them
642
+ CustomStateStruct *CustomStates = CustomState.State ;
643
+ if (CustomStates)
644
+ {
645
+ delete[] (CustomStates);
646
+ CustomState.State = nullptr ;
647
+ }
648
+
624
649
uint32_t tempTotalCustomStates = Settings->CustomStateSettings .CustomStateCount ;
650
+ uint32_t tempTotalCustomStatesSize;
651
+ CustomStateStruct *tempState;
652
+
625
653
if (tempTotalCustomStates > 0 )
626
654
{
627
655
if (tempTotalCustomStates > CUSTOM_STATES_MAX_COUNT)
628
656
{
629
657
tempTotalCustomStates = CUSTOM_STATES_MAX_COUNT;
630
658
}
631
659
632
- CustomState.TotalEntries = tempTotalCustomStates;
633
- CustomState.StateWasSelected = false ;
634
-
635
- CustomStateStruct *tempState = CustomState.State ;
636
- if (tempState)
637
- {
638
- delete[] (tempState);
639
- }
640
-
641
- tempState = new CustomStateStruct[tempTotalCustomStates];
642
- CustomState.State = tempState;
660
+ tempTotalCustomStatesSize = sizeof (CustomStateStruct) * tempTotalCustomStates;
643
661
644
662
CustomStateStruct *CustomStatesSettings = reinterpret_cast <CustomStateStruct *>(
645
663
reinterpret_cast <uint32_t >(Settings) + Settings->CustomStateSettings .OffsetToCustomStates );
646
664
647
- memcpy (tempState, CustomStatesSettings, sizeof (CustomStateStruct) * tempTotalCustomStates);
665
+ tempState = new CustomStateStruct[tempTotalCustomStates];
666
+ memcpy (tempState, CustomStatesSettings, tempTotalCustomStatesSize);
648
667
}
649
668
650
- // Get the hit check visualization data
651
- HitCheck.Settings .DrawHits = Settings->HitCheckSettings .DrawHits ;
652
- HitCheck.Settings .DrawMisses = Settings->HitCheckSettings .DrawMisses ;
653
-
654
- // Only get the colors if their alphas are not 0
655
- uint32_t HitsColor = Settings->HitCheckSettings .HitsColor ;
656
- if ((HitsColor & 0xFF ) != 0 )
657
- {
658
- HitCheck.Settings .HitsColor = HitsColor;
659
- }
669
+ delete[] (MiscData);
660
670
661
- uint32_t MissesColor = Settings-> HitCheckSettings . MissesColor ;
662
- if ((MissesColor & 0xFF ) != 0 )
671
+ // If there are any custom states, reallocate memory for them now to avoid fragmentation
672
+ if (tempTotalCustomStates > 0 )
663
673
{
664
- HitCheck.Settings .MissesColor = MissesColor;
674
+ CustomStates = new CustomStateStruct[tempTotalCustomStates];
675
+
676
+ CustomState.State = CustomStates;
677
+ CustomState.TotalEntries = static_cast <uint8_t >(tempTotalCustomStates);
678
+ memcpy (CustomStates, tempState, tempTotalCustomStatesSize);
679
+
680
+ delete[] (tempState);
665
681
}
666
682
667
- delete[] (MiscData);
668
683
return CARD_RESULT_READY;
669
684
}
670
685
0 commit comments