Skip to content

Commit 816ca04

Browse files
XD
1 parent a2a3e6a commit 816ca04

File tree

7 files changed

+432
-34
lines changed

7 files changed

+432
-34
lines changed

README.md

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ local function OnDraw()
4949
print("Current slider value:", sliderValue)
5050

5151
end
52+
TimMenu.End() -- Always call End() to clean up
5253
end
5354

5455
callbacks.Register("Draw", "ExampleDraw", OnDraw)
@@ -59,6 +60,9 @@ callbacks.Register("Draw", "ExampleDraw", OnDraw)
5960
### Window Management
6061

6162
- Begin: `bool = TimMenu.Begin(title, [visible, [id]])`
63+
- BeginSafe: `bool = TimMenu.BeginSafe(title, [visible, [id]])` - Safe version with error handling
64+
- End: `TimMenu.End()` - Always call to clean up window state
65+
- EndSafe: `TimMenu.EndSafe()` - Safe version with error handling
6266

6367
### Layout
6468

@@ -118,6 +122,7 @@ local function OnDraw()
118122
selectedOption = TimMenu.Dropdown("Quality", selectedOption, options)
119123
end
120124
end
125+
TimMenu.End() -- Always call End() to clean up
121126
end
122127
```
123128

@@ -132,6 +137,7 @@ local function OnDraw()
132137
TimMenu.Text(string.format("RGB: %d, %d, %d, %d",
133138
backgroundColor[1], backgroundColor[2], backgroundColor[3], backgroundColor[4]))
134139
end
140+
TimMenu.End() -- Always call End() to clean up
135141
end
136142
```
137143

@@ -152,15 +158,61 @@ local function OnDraw()
152158
end
153159
end
154160
end
161+
TimMenu.End() -- Always call End() to clean up
155162
end
156163
```
157164

158-
## Tips
165+
## Recommended Safe Usage Pattern
159166

160-
- Use `BeginSector`/`EndSector` to group widgets in bordered panels.
161-
- Sectors can be easily stacked horizontally and vertically
162-
- All widgets return their current value - no need to track "changed" flags
163-
- Values are automatically maintained between frames by the widget system
167+
For robust menu creation, use the safe versions of Begin/End with proper error handling:
168+
169+
```lua
170+
local TimMenu = require("TimMenu")
171+
172+
local function CreateSafeMenu()
173+
if TimMenu.BeginSafe("My Safe Menu") then
174+
-- Your widgets here
175+
local value = TimMenu.Slider("Test Slider", 50, 0, 100, 1)
176+
if TimMenu.Button("Test Button") then
177+
print("Button clicked!")
178+
end
179+
end
180+
TimMenu.EndSafe() -- Always called, even if there are errors
181+
end
182+
183+
callbacks.Register("Draw", "SafeMenu", CreateSafeMenu)
184+
```
185+
186+
## Error Detection and Debugging
187+
188+
TimMenu now includes comprehensive assertions and error checking to help debug issues:
189+
190+
### Assertion Coverage
191+
192+
- **Parameter validation** - All functions validate input parameters with detailed error messages
193+
- **Window state validation** - Ensures windows are in valid states before operations
194+
- **Layout validation** - Catches layout issues like infinite expansion, invalid spacing
195+
- **Widget usage validation** - Ensures widgets are only called within Begin/End blocks
196+
- **Dimension validation** - Prevents windows from growing beyond reasonable limits (5000px threshold)
197+
- **Position validation** - Detects invalid window positions that could cause issues
198+
199+
### Common Error Messages
200+
201+
When assertions fail, you'll see detailed error messages like:
202+
```
203+
[TimMenu] Begin: Parameter 'title' cannot be empty string
204+
[TimMenu] AddWidget: Window dimensions too large W=6000, H=3000 (possible infinite expansion)
205+
[TimMenu] NextLine: Must be called between TimMenu.Begin() and TimMenu.End()
206+
[TimMenu] Slider: min (50) must be less than max (25)
207+
[TimMenu] Dropdown: options table cannot be empty
208+
```
209+
210+
### Debugging Tips
211+
212+
- **Enable assertions** by running in debug mode - they help catch issues early
213+
- **Check error messages** carefully - they tell you exactly what went wrong and where
214+
- **Use BeginSafe/EndSafe** for production code to handle assertion failures gracefully
215+
- **Monitor window dimensions** - if windows grow beyond 5000px, there's likely an infinite expansion bug
164216

165217
## Sector Grouping
166218

@@ -176,6 +228,7 @@ if TimMenu.Begin("Example Window") then
176228
local volume = TimMenu.Slider("Volume", 50, 0, 100, 1)
177229
TimMenu.EndSector()
178230
end
231+
TimMenu.End() -- Always call End() to clean up
179232
```
180233

181234
## Changelog
@@ -192,9 +245,16 @@ end
192245

193246
- Keybind widget now recalculates its display label immediately after a key press and dynamically computes its draw position inside the rendering callback, eliminating frame delay when dragging windows.
194247

195-
### Fixed TabControl Header Lag
248+
### Added Comprehensive Assertions and Error Detection
196249

197-
- Header-mode tabs now calculate their offsets relative to the window's current position at draw time, preventing one-frame lag during window movement.
250+
- **Complete assertion coverage** - Added parameter validation, state checks, and error detection throughout the codebase
251+
- **Detailed error messages** - All assertion failures provide specific information about what went wrong and where
252+
- **Window dimension limits** - Added 5000px threshold to catch infinite expansion issues early
253+
- **Layout validation** - Added checks for invalid spacing, cursor positions, and widget placement
254+
- **Widget usage validation** - Ensures all widgets are called within proper Begin/End blocks
255+
- **Parameter type checking** - Validates all function parameters with descriptive error messages
256+
- **Safe wrapper functions** - BeginSafe() and EndSafe() provide error handling for production use
257+
- **Debugging documentation** - Added comprehensive debugging guide with common error patterns
198258

199259
## License
200260

0 commit comments

Comments
 (0)