summary refs log tree commit diff stats
path: root/widgets
diff options
context:
space:
mode:
authorKevin Kuehler <keur@ocf.berkeley.edu>2019-05-25 02:06:15 -0700
committerDrew DeVault <sir@cmpwn.com>2019-06-01 11:09:14 -0400
commit3445b80d7a710edf72088d6faea1f640988b1766 (patch)
treeea8e4feca11d26b07a26e6331441baa0b9dd80ca /widgets
parent0bfb90baedbde0bb5a862e6a8fe9ec7e56d664e5 (diff)
downloadaerc-3445b80d7a710edf72088d6faea1f640988b1766.tar.gz
widgets/terminal: Don't segfault on resize
vterm.Write and vterm.SetSize race when the window resizes, which
causing the underlying library to segfault.

Signed-off-by: Kevin Kuehler <keur@ocf.berkeley.edu>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/terminal.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/widgets/terminal.go b/widgets/terminal.go
index ecb26aa..82190cc 100644
--- a/widgets/terminal.go
+++ b/widgets/terminal.go
@@ -101,8 +101,9 @@ type Terminal struct {
 	start       chan interface{}
 	vterm       *vterm.VTerm
 
-	damage []vterm.Rect // protected by mutex
-	mutex  sync.Mutex
+	damage []vterm.Rect // protected by damageMutex
+	damageMutex sync.Mutex
+	writeMutex  sync.Mutex
 
 	OnClose func(err error)
 	OnEvent func(event tcell.Event) bool
@@ -129,7 +130,9 @@ func NewTerminal(cmd *exec.Cmd) (*Terminal, error) {
 				term.Close(nil)
 				return
 			}
+			term.writeMutex.Lock()
 			n, err = term.vterm.Write(buf[:n])
+			term.writeMutex.Unlock()
 			if err != nil {
 				term.Close(err)
 				return
@@ -204,9 +207,9 @@ func (term *Terminal) Invalidate() {
 	if term.vterm != nil {
 		width, height := term.vterm.Size()
 		rect := vterm.NewRect(0, width, 0, height)
-		term.mutex.Lock()
+		term.damageMutex.Lock()
 		term.damage = append(term.damage, *rect)
-		term.mutex.Unlock()
+		term.damageMutex.Unlock()
 	}
 	term.invalidate()
 }
@@ -247,12 +250,14 @@ func (term *Terminal) Draw(ctx *ui.Context) {
 			return
 		}
 		if ctx.Width() != cols || ctx.Height() != rows {
+			term.writeMutex.Lock()
 			pty.Setsize(term.pty, &winsize)
 			term.vterm.SetSize(ctx.Height(), ctx.Width())
+			term.writeMutex.Unlock()
 			rect := vterm.NewRect(0, ctx.Width(), 0, ctx.Height())
-			term.mutex.Lock()
+			term.damageMutex.Lock()
 			term.damage = append(term.damage, *rect)
-			term.mutex.Unlock()
+			term.damageMutex.Unlock()
 			return
 		}
 	}
@@ -267,7 +272,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
 	// naive optimization
 	visited := make(map[coords]interface{})
 
-	term.mutex.Lock()
+	term.damageMutex.Lock()
 	for _, rect := range term.damage {
 		for x := rect.StartCol(); x < rect.EndCol() && x < ctx.Width(); x += 1 {
 
@@ -290,7 +295,7 @@ func (term *Terminal) Draw(ctx *ui.Context) {
 	}
 
 	term.damage = nil
-	term.mutex.Unlock()
+	term.damageMutex.Unlock()
 
 	if term.focus && !term.closed {
 		if !term.cursorShown {
@@ -414,9 +419,9 @@ func (term *Terminal) styleFromCell(cell *vterm.ScreenCell) tcell.Style {
 }
 
 func (term *Terminal) onDamage(rect *vterm.Rect) int {
-	term.mutex.Lock()
+	term.damageMutex.Lock()
 	term.damage = append(term.damage, *rect)
-	term.mutex.Unlock()
+	term.damageMutex.Unlock()
 	term.invalidate()
 	return 1
 }
e='Blame the previous revision' href='/akspecs/ranger/blame/test/tc_directory.py?h=v1.5.3&id=6ca37350f8e6bffe78520fddfc29ca53fa562e87'>^
fe179145 ^
fae694a0 ^
fe179145 ^
5822dff7 ^
9506fb8e ^
fae694a0 ^
9506fb8e ^
fae694a0 ^
fe179145 ^

fae694a0 ^
fe179145 ^
fae694a0 ^


4c05e43d ^

fae694a0 ^

fe179145 ^

fae694a0 ^




9506fb8e ^
fae694a0 ^
fae694a0 ^
1159f9ec ^



fe179145 ^
5822dff7 ^
9506fb8e ^
fae694a0 ^
fe179145 ^
fae694a0 ^
fe179145 ^

fae694a0 ^

fe179145 ^
fae694a0 ^
9506fb8e ^

f6f26231 ^
4c05e43d ^
f6f26231 ^







9506fb8e ^
fae694a0 ^

f6f26231 ^










4c05e43d ^

fae694a0 ^

fe179145 ^
5822dff7 ^

fe179145 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103