Skip to content

Commit d1adcca

Browse files
committed
fixed imgui related crashes caused by parent window being too small
the crashes are caused by BeginTable() failing and then EndTable() being called. Or BeginChild() failing and EndChild not being called.
1 parent 5213c4e commit d1adcca

File tree

8 files changed

+40
-26
lines changed

8 files changed

+40
-26
lines changed

gui/sdlimgui/win_6507_pinout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ func (win *win6507Pinout) draw() {
243243
win.bodyOutline, 0, imgui.DrawCornerFlagsAll, lineThick)
244244

245245
imgui.PopFont()
246-
imgui.EndChild()
247246
}
247+
imgui.EndChild()
248248

249249
// bus information
250250
win.busInfoHeight = imguiMeasureHeight(func() {

gui/sdlimgui/win_cart_cdf_streams.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,8 @@ func (win *winCDFStreams) draw(regs cdf.Registers, static mapper.CartStatic) {
393393
imgui.EndGroup()
394394
imgui.SameLine()
395395
}
396-
397-
imgui.EndChild()
398396
}
397+
imgui.EndChild()
399398

400399
win.optionsHeight = imguiMeasureHeight(func() {
401400
imgui.Spacing()

gui/sdlimgui/win_coproc_disasm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ func (win *winCoProcDisasm) draw() {
120120
imgui.Text("Coprocessor disassembly is disabled")
121121
}
122122

123-
imgui.EndChild()
124123
}
124+
imgui.EndChild()
125125

126126
// draw options and status line. start height measurement
127127
win.optionsHeight = imguiMeasureHeight(func() {

gui/sdlimgui/win_coproc_functions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ func (win *winCoProcFunctions) draw() {
9292
flgs |= imgui.TableFlagsSizingStretchProp
9393
flgs |= imgui.TableFlagsResizable
9494
flgs |= imgui.TableFlagsHideable
95-
imgui.BeginTableV("##coprocFunctionsTable", numColumns, flgs, imgui.Vec2{}, 0.0)
95+
if !imgui.BeginTableV("##coprocFunctionsTable", numColumns, flgs, imgui.Vec2{}, 0.0) {
96+
return
97+
}
9698

9799
width := imgui.ContentRegionAvail().X
98100
imgui.TableSetupColumnV("Name", imgui.TableColumnFlagsPreferSortDescending|imgui.TableColumnFlagsNoHide, width*0.5, 0)

gui/sdlimgui/win_coproc_globals.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ func (win *winCoProcGlobals) draw() {
188188
flgs |= imgui.TableFlagsSortable
189189
flgs |= imgui.TableFlagsResizable
190190

191-
imgui.BeginTableV("##globalsTable", numColumns, flgs, imgui.Vec2{Y: imguiRemainingWinHeight() - win.optionsHeight}, 0.0)
191+
if imgui.BeginTableV("##globalsTable", numColumns, flgs, imgui.Vec2{Y: imguiRemainingWinHeight() - win.optionsHeight}, 0.0) {
192+
return
193+
}
192194

193195
// setup columns. the labelling column 2 depends on whether the coprocessor
194196
// development instance has source available to it

gui/sdlimgui/win_coproc_locals.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ func (win *winCoProcLocals) draw() {
108108
flgs |= imgui.TableFlagsResizable
109109
flgs |= imgui.TableFlagsHideable
110110

111-
imgui.BeginTableV("##localsTable", numColumns, flgs, imgui.Vec2{Y: imguiRemainingWinHeight() - win.optionsHeight}, 0.0)
111+
if !imgui.BeginTableV("##localsTable", numColumns, flgs, imgui.Vec2{Y: imguiRemainingWinHeight() - win.optionsHeight}, 0.0) {
112+
return
113+
}
112114

113115
// setup columns. the labelling column 2 depends on whether the coprocessor
114116
// development instance has source available to it

gui/sdlimgui/win_disasm.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ func (win *winDisasm) drawOptions(currBank mapper.BankInfo) {
311311
})
312312
}
313313

314-
func (win *winDisasm) startTable() {
314+
func (win *winDisasm) startTable() bool {
315315
numColumns := 6
316316
flgs := imgui.TableFlagsNone
317317
flgs |= imgui.TableFlagsSizingFixedFit
318318
if !imgui.BeginTableV("bank", numColumns, flgs, imgui.Vec2{}, 0) {
319-
return
319+
return false
320320
}
321321

322322
operandWidth := imgui.ContentRegionAvail().X - imgui.CurrentStyle().ItemSpacing().X*float32(numColumns)
@@ -328,6 +328,8 @@ func (win *winDisasm) startTable() {
328328
imgui.TableSetupColumnV("##operand", imgui.TableColumnFlagsNone, operandWidth, 3)
329329
imgui.TableSetupColumnV("##cycles", imgui.TableColumnFlagsNone, win.widthCycles, 4)
330330
imgui.TableSetupColumnV("##notes", imgui.TableColumnFlagsNone, win.widthNotes, 5)
331+
332+
return true
331333
}
332334

333335
// drawBank specified by bank argument.
@@ -386,14 +388,17 @@ func (win *winDisasm) drawBank(currBank mapper.BankInfo, focusAddr uint16) {
386388
}
387389

388390
// iterateDraw presents the entry according to the current rules
389-
iterateDraw := func(e *disassembly.Entry) {
391+
iterateDraw := func(e *disassembly.Entry) bool {
390392
if headerRequired {
391393
imgui.EndTable()
392394
imgui.Text(fmt.Sprintf("Bank %d", iterateBank))
393-
win.startTable()
395+
if !win.startTable() {
396+
return false
397+
}
394398
headerRequired = false
395399
}
396400
win.drawEntry(currBank, e, focusAddr, onBank, iterateBank)
401+
return true
397402
}
398403

399404
// alter iterate functions according to selected filter
@@ -413,15 +418,18 @@ func (win *winDisasm) drawBank(currBank mapper.BankInfo, focusAddr uint16) {
413418
iterateIdx++
414419
return iterateIdx < len(dsmEntries.Entries[iterateBank])
415420
}
416-
iterateDraw = func(e *disassembly.Entry) {
421+
iterateDraw = func(e *disassembly.Entry) bool {
417422
if e == nil {
418-
return
423+
return true
419424
}
420425
win.drawLabel(e, iterateBank)
421426
win.drawEntry(currBank, e, focusAddr, onBank, iterateBank)
422427
if currBank.ExecutingCoprocessor && onBank && e.Result.Address&memorymap.CartridgeBits == focusAddr {
423-
win.drawEntryCoProcessorExecution()
428+
if !win.drawEntryCoProcessorExecution() {
429+
return false
430+
}
424431
}
432+
return true
425433
}
426434
case filterCPUBug:
427435
iterateFilter = func(e *disassembly.Entry) bool {
@@ -476,7 +484,9 @@ func (win *winDisasm) drawBank(currBank mapper.BankInfo, focusAddr uint16) {
476484
return
477485
}
478486

479-
win.startTable()
487+
if !win.startTable() {
488+
return
489+
}
480490

481491
// wrap list clipper in anonymous function call. convenient to just
482492
// return from the function from inside a nested loop
@@ -571,42 +581,41 @@ func (win *winDisasm) drawBank(currBank mapper.BankInfo, focusAddr uint16) {
571581
imgui.EndChild()
572582
}
573583

574-
func (win *winDisasm) drawLabel(e *disassembly.Entry, bank int) {
584+
func (win *winDisasm) drawLabel(e *disassembly.Entry, bank int) bool {
575585
if len(e.Label.Resolve()) == 0 {
576-
return
586+
return true
577587
}
578588

579589
// end existing disasm table before drawing label. (re)start table before
580590
// the end of the function
581591
imgui.EndTable()
582-
defer win.startTable()
583592

584593
imgui.PushStyleColor(imgui.StyleColorHeaderHovered, win.img.cols.DisasmHover)
585594
imgui.PushStyleColor(imgui.StyleColorHeaderActive, win.img.cols.DisasmHover)
586-
defer imgui.PopStyleColorV(2)
587595
imgui.SelectableV("", false, imgui.SelectableFlagsNone, imgui.Vec2{0, 0})
588596
imgui.SameLine()
589-
590597
imgui.Text(e.Label.Resolve())
598+
imgui.PopStyleColorV(2)
599+
600+
return win.startTable()
591601
}
592602

593603
func (win *winDisasm) drawCoProcTooltip() {
594604
win.img.imguiTooltipSimple("Coprocessor is executing")
595605
}
596606

597-
func (win *winDisasm) drawEntryCoProcessorExecution() {
607+
func (win *winDisasm) drawEntryCoProcessorExecution() bool {
598608
imgui.EndTable()
599-
defer win.startTable()
600609

601610
imgui.PushStyleColor(imgui.StyleColorHeaderHovered, win.img.cols.DisasmHover)
602611
imgui.PushStyleColor(imgui.StyleColorHeaderActive, win.img.cols.DisasmHover)
603-
defer imgui.PopStyleColorV(2)
604612
imgui.SelectableV("", false, imgui.SelectableFlagsNone, imgui.Vec2{0, 0})
605-
606613
win.drawCoProcTooltip()
607-
608614
imgui.SameLine()
609615
imgui.Text(fmt.Sprintf(" %c 6507 will resume here", fonts.CoProcExecution))
616+
imgui.PopStyleColorV(2)
617+
618+
return win.startTable()
610619
}
611620

612621
func (win *winDisasm) drawEntry(currBank mapper.BankInfo, e *disassembly.Entry, focusAddr uint16, onBank bool, bank int) {

gui/sdlimgui/win_terminal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ func (win *winTerm) debuggerDraw() bool {
135135
imgui.SetScrollHereY(0.0)
136136
}
137137

138-
imgui.EndChild()
139138
}
139+
imgui.EndChild()
140140

141141
// context menu for scrollback area
142142
if imgui.BeginPopupContextItem() {

0 commit comments

Comments
 (0)