fix: emergency memory optimization to prevent Stack-Heap Collision

CRITICAL FIX: Main Controller experiencing Stack-Heap Collision from verbose logging

- Added emergency memory monitoring to auto-disable verbose logging when memory low
- Replaced heavy string concatenation debug calls with lightweight versions
- Added memory checks before debug output to prevent crashes
- Simplified verbose logging toggle messages to reduce memory usage
- Emergency threshold: auto-disable at <1000 bytes free memory
- Safety checks: only output debug if >500 bytes available

This should immediately resolve the Stack-Heap Collision error.
This commit is contained in:
RebeccaNod1 2025-09-14 09:39:06 -05:00
parent 56c74a03f5
commit bb06bf74dd

View file

@ -83,6 +83,29 @@ integer DEBUG_PICKS = FALSE;
// Verbose logging system - affects all modules when toggled // Verbose logging system - affects all modules when toggled
integer VERBOSE_LOGGING = FALSE; integer VERBOSE_LOGGING = FALSE;
// Emergency memory management - disable verbose logging if memory gets low
emergencyMemoryCheck() {
if (llGetFreeMemory() < 1000) {
VERBOSE_LOGGING = FALSE;
llOwnerSay("⚠️ Low memory detected - auto-disabling verbose logging");
}
}
// Memory-efficient debug function to prevent Stack-Heap Collision
debugMsg(string msg) {
emergencyMemoryCheck();
if (VERBOSE_LOGGING && llGetFreeMemory() > 500) {
llOwnerSay("[M] " + msg);
}
}
// Ultra-light debug for critical paths only
lightDebug(string msg) {
if (VERBOSE_LOGGING && llGetFreeMemory() > 300) {
llOwnerSay(msg);
}
}
// Status message timing // Status message timing
float STATUS_DISPLAY_TIME = 8.0; // How long to show status messages on scoreboard float STATUS_DISPLAY_TIME = 8.0; // How long to show status messages on scoreboard
integer statusTimer = 0; // Track when status messages were sent integer statusTimer = 0; // Track when status messages were sent
@ -460,8 +483,8 @@ default {
if (currentPickerIdx < llGetListLength(pickQueue)) { if (currentPickerIdx < llGetListLength(pickQueue)) {
string expectedPickerName = llList2String(pickQueue, currentPickerIdx); string expectedPickerName = llList2String(pickQueue, currentPickerIdx);
if (VERBOSE_LOGGING) { if (VERBOSE_LOGGING) {
llOwnerSay("🔍 [Touch Debug] Player: " + playerName + ", Expected picker: " + expectedPickerName + ", PickerIdx: " + (string)currentPickerIdx); debugMsg("Touch: " + playerName + " exp:" + expectedPickerName);
llOwnerSay("🔍 [Touch Debug] CurrentPicker: " + (string)currentPicker + ", Toucher: " + (string)toucher); debugMsg("Idx:" + (string)currentPickerIdx);
} }
if (playerName == expectedPickerName) { if (playerName == expectedPickerName) {
shouldBePicking = TRUE; shouldBePicking = TRUE;
@ -473,7 +496,7 @@ default {
} }
} }
} else if (VERBOSE_LOGGING) { } else if (VERBOSE_LOGGING) {
llOwnerSay("🔍 [Touch Debug] Pick phase complete - currentPickerIdx (" + (string)currentPickerIdx + ") >= pickQueue length (" + (string)llGetListLength(pickQueue) + ")"); debugMsg("Pick phase done - idx >= queue len");
} }
// FALLBACK: If game is stuck and no one is set as current picker, but we're in pick phase, // FALLBACK: If game is stuck and no one is set as current picker, but we're in pick phase,
@ -1127,11 +1150,11 @@ default {
if (num == 9010 && str == "TOGGLE_VERBOSE_LOGS") { if (num == 9010 && str == "TOGGLE_VERBOSE_LOGS") {
VERBOSE_LOGGING = !VERBOSE_LOGGING; VERBOSE_LOGGING = !VERBOSE_LOGGING;
if (VERBOSE_LOGGING) { if (VERBOSE_LOGGING) {
llOwnerSay("🔍 [Main Controller] Verbose logging turned ON"); llOwnerSay("Debug: ON");
llSay(0, "🔍 Verbose logging system-wide: ON"); llSay(0, "Debug: ON");
} else { } else {
llOwnerSay("🔍 [Main Controller] Verbose logging turned OFF"); llOwnerSay("Debug: OFF");
llSay(0, "🔍 Verbose logging system-wide: OFF"); llSay(0, "Debug: OFF");
} }
// Broadcast the setting to all modules // Broadcast the setting to all modules