mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2024-11-28 12:22:20 -05:00
fix: don't crash when changing margins (#2828)
for some reason we were getting garbage data in cvarNameMargins when doing things the `const char *` way. i wasn't able to figure out why that was getting garbage but this makes it so we don't get garbage in there Co-authored-by: briaguya <briaguya@alice>
This commit is contained in:
parent
d025ca0d90
commit
c3ba15ed57
@ -345,28 +345,26 @@ ImVec4 GetRandomValue(int MaximumPossible){
|
|||||||
|
|
||||||
void SetMarginAll(const char* ButtonName, bool SetActivated) {
|
void SetMarginAll(const char* ButtonName, bool SetActivated) {
|
||||||
if (ImGui::Button(ButtonName)) {
|
if (ImGui::Button(ButtonName)) {
|
||||||
u8 arrayLength = sizeof(MarginCvarList) / sizeof(*MarginCvarList);
|
|
||||||
//MarginCvarNonAnchor is an array that list every element that has No anchor by default, because if that the case this function will not touch it with pose type 0.
|
//MarginCvarNonAnchor is an array that list every element that has No anchor by default, because if that the case this function will not touch it with pose type 0.
|
||||||
u8 arrayLengthNonMargin = sizeof(MarginCvarNonAnchor) / sizeof(*MarginCvarNonAnchor);
|
u8 arrayLengthNonMargin = sizeof(MarginCvarNonAnchor) / sizeof(*MarginCvarNonAnchor);
|
||||||
for (u8 s = 0; s < arrayLength; s++) {
|
for (auto cvarName : MarginCvarList) {
|
||||||
const char* cvarName = MarginCvarList[s];
|
std::string cvarPosType = std::string(cvarName).append("PosType");
|
||||||
const char* cvarPosType = std::string(cvarName).append("PosType").c_str();
|
std::string cvarNameMargins = std::string(cvarName).append("UseMargins");
|
||||||
const char* cvarNameMargins = std::string(cvarName).append("UseMargins").c_str();
|
if (CVarGetInteger(cvarPosType.c_str(),0) <= 2 && SetActivated) { //Our element is not Hidden or Non anchor
|
||||||
if (CVarGetInteger(cvarPosType,0) <= 2 && SetActivated) { //Our element is not Hidden or Non anchor
|
|
||||||
for (int i = 0; i < arrayLengthNonMargin; i++){
|
for (int i = 0; i < arrayLengthNonMargin; i++){
|
||||||
if ((strcmp(cvarName, MarginCvarNonAnchor[i]) == 0) && (CVarGetInteger(cvarPosType, 0) == 0)) { //Our element is both in original position and do not have anchor by default so we skip it.
|
if ((strcmp(cvarName, MarginCvarNonAnchor[i]) == 0) && (CVarGetInteger(cvarPosType.c_str(), 0) == 0)) { //Our element is both in original position and do not have anchor by default so we skip it.
|
||||||
CVarSetInteger(cvarNameMargins, false); //force set off
|
CVarSetInteger(cvarNameMargins.c_str(), false); //force set off
|
||||||
}
|
}
|
||||||
else if ((strcmp(cvarName, MarginCvarNonAnchor[i]) == 0) && (CVarGetInteger(cvarPosType, 0) != 0)) { //Our element is not in original position regarless it has no anchor by default since player made it anchored we can toggle margins
|
else if ((strcmp(cvarName, MarginCvarNonAnchor[i]) == 0) && (CVarGetInteger(cvarPosType.c_str(), 0) != 0)) { //Our element is not in original position regarless it has no anchor by default since player made it anchored we can toggle margins
|
||||||
CVarSetInteger(cvarNameMargins, SetActivated);
|
CVarSetInteger(cvarNameMargins.c_str(), SetActivated);
|
||||||
}
|
}
|
||||||
else if (strcmp(cvarName, MarginCvarNonAnchor[i]) != 0) { //Our elements has an anchor by default so regarless of it's position right now that okay to toggle margins.
|
else if (strcmp(cvarName, MarginCvarNonAnchor[i]) != 0) { //Our elements has an anchor by default so regarless of it's position right now that okay to toggle margins.
|
||||||
CVarSetInteger(cvarNameMargins, SetActivated);
|
CVarSetInteger(cvarNameMargins.c_str(), SetActivated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { //Since the user requested to turn all margin off no need to do any check there.
|
else { //Since the user requested to turn all margin off no need to do any check there.
|
||||||
CVarSetInteger(cvarNameMargins, SetActivated);
|
CVarSetInteger(cvarNameMargins.c_str(), SetActivated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user