nelsam / vidar

vidar is a highly experimental Go editor, written in Go, using gxui
The Unlicense
50 stars 7 forks source link

Panic while executing bindable *history.Undo: runtime error: slice bounds out of range #188

Open Kvaz1r opened 4 years ago

Kvaz1r commented 4 years ago

Description

Unexpectedly got such log message: 2019/12/27 18:59:43 ERR: panic while executing bindable *history.Undo: runtime error: slice bounds out of range

Steps to reproduce

  1. Not found yet

Stack trace

2019/12/27 18:59:43 Stack trace: goroutine 19 [running]: runtime/debug.Stack(0xa552dd, 0x2a, 0xc0007bf190) c:/go/src/runtime/debug/stack.go:24 +0xae github.com/nelsam/vidar/commander.(Commander).Execute.func1(0xaa87a0, 0xc0000c08c0) T:/libraries/Gopath/src/github.com/nelsam/vidar/commander/commander.go:337 +0xc0 panic(0x9a71a0, 0x8cfb30) c:/go/src/runtime/panic.go:513 +0x1c7 github.com/nelsam/vidar/command/input.(Handler).Apply(0xc0001bb700, 0xaae5a0, 0xc000a83c00, 0xc0005661c0, 0x1, 0x1) T:/libraries/Gopath/src/github.com/nelsam/vidar/command/input/handler.go:138 +0xa42 github.com/nelsam/vidar/command/history.(Undo).Exec(0xc0000c08c0, 0xa15820, 0xc000004520) T:/libraries/Gopath/src/github.com/nelsam/vidar/command/history/undo_redo.go:92 +0x154 github.com/nelsam/vidar/commander.(Commander).Execute(0xc00004d180, 0xaa87a0, 0xc0000c08c0) T:/libraries/Gopath/src/github.com/nelsam/vidar/commander/commander.go:353 +0x380 github.com/nelsam/vidar/commander.(Commander).KeyPress(0xc00004d180, 0x2c, 0x2, 0xab2600) T:/libraries/Gopath/src/github.com/nelsam/vidar/commander/commander.go:299 +0x1a6 github.com/nelsam/gxui.(KeyboardController).keyPress(0xc0002cf820, 0x2c, 0x2) T:/libraries/Gopath/src/github.com/nelsam/gxui/keyboard_controller.go:42 +0xb8 github.com/nelsam/gxui.(KeyboardController).keyDown(0xc0002cf820, 0x2c, 0x2) T:/libraries/Gopath/src/github.com/nelsam/gxui/keyboard_controller.go:28 +0xda github.com/nelsam/gxui.(KeyboardController).keyDown-fm(0x2c, 0x2) T:/libraries/Gopath/src/github.com/nelsam/gxui/keyboard_controller.go:15 +0x45 reflect.Value.call(0x93a280, 0xc0002cf830, 0x13, 0xa388c5, 0x4, 0xc00045d120, 0x1, 0x1, 0xa1e340, 0xc0007bfa01, ...) c:/go/src/reflect/value.go:447 +0x45b reflect.Value.Call(0x93a280, 0xc0002cf830, 0x13, 0xc00045d120, 0x1, 0x1, 0x9fcc40, 0x1, 0xc00021bc00) c:/go/src/reflect/value.go:308 +0xab github.com/nelsam/gxui.(EventBase).InvokeListeners(0xc00029a370, 0xc00021bbf0, 0x1, 0x1) T:/libraries/Gopath/src/github.com/nelsam/gxui/event_base.go:140 +0x1cf github.com/nelsam/gxui.(EventBase).Fire(0xc00029a370, 0xc00021bbf0, 0x1, 0x1) T:/libraries/Gopath/src/github.com/nelsam/gxui/event_base.go:190 +0x7c github.com/nelsam/gxui/mixins.(Window).setViewport.func9(0x2c, 0x2) T:/libraries/Gopath/src/github.com/nelsam/gxui/mixins/window.go:386 +0xcc reflect.Value.call(0x93a280, 0xc0002cfaa0, 0x13, 0xa388c5, 0x4, 0xc00045d100, 0x1, 0x1, 0xa1e340, 0xc0007bff01, ...) c:/go/src/reflect/value.go:447 +0x45b reflect.Value.Call(0x93a280, 0xc0002cfaa0, 0x13, 0xc00045d100, 0x1, 0x1, 0xc0007bff40, 0x42e478, 0xa5ec18) c:/go/src/reflect/value.go:308 +0xab github.com/nelsam/gxui.(EventBase).InvokeListeners(0xc0000c1cf8, 0xc0003a9270, 0x1, 0x1) T:/libraries/Gopath/src/github.com/nelsam/gxui/event_base.go:140 +0x1cf github.com/nelsam/gxui.(ChanneledEvent).Fire.func1() T:/libraries/Gopath/src/github.com/nelsam/gxui/channeled_event.go:40 +0x6f github.com/nelsam/gxui/drivers/gl.(driver).applicationLoop(0xc00009e410) T:/libraries/Gopath/src/github.com/nelsam/gxui/drivers/gl/driver.go:141 +0x2b created by github.com/nelsam/gxui/drivers/gl.StartDriver T:/libraries/Gopath/src/github.com/nelsam/gxui/drivers/gl/driver.go:84 +0x35a

Kvaz1r commented 4 years ago

Ok, I found how it can be reproduce:

  1. Open any file {1}
  2. Create new file {2} and insert some text
  3. Select first file via panel_holder
  4. Press Ctrl+Z
  5. Changes from {2} will try to been applied to {1} file. {1} will corrupted {1} if range fits otherwise getting panic from title.

Very unpleasant bug, I am very glad that started to use git even for small projects :)

Kvaz1r commented 4 years ago

It seems that oldPath and path in Location.Exec/0 not equal only while file are opening. After that click on different tabs doesn't change the value. Quick workaround - to remove condition. Edit: No, it doesn't fix the behaviour.

nelsam commented 4 years ago

It looks like this is largely because we're relying on side effects from gxui's PanelHolder mixin. We'll need to build a custom one that doesn't automatically switch tabs, so that we can have the PanelHolder's click events trigger our focus.Location op.

I'll dig in to it. I should be able to get a quick workaround built before too long. For now, try to use ctrl+tab and ctrl+shift+tab to switch tabs.

Kvaz1r commented 4 years ago

I'm not sure that such solution will be the best one because it's bind vidar to gxui even more and this way maybe require many changes. And focus.Location op already called when tab changes that's not the problem. The key is in condition because in case selecting tab there isn't editor that gives focus from his own to selected one.

Maybe really just slightly extend/modify FileChanger with method that take single argument - new filename? I can try to do so on the week.

Kvaz1r commented 4 years ago

It was even simple than I thought - https://github.com/Kvaz1r/vidar/commit/cfd501cb7979b04a74a560a05d5bcbfee78073c9