VedVid / RAWIG

RAWIG (Roguelike Architecture, Written In Go) is ready to modify and expand roguelike architecture.
BSD 2-Clause "Simplified" License
16 stars 3 forks source link

Crash during removing item from inventory #72

Closed VedVid closed 5 years ago

VedVid commented 5 years ago

FindObjectIndex in utilities_math.go and EquipItem in monsters.go

*Object not found in []*Object.
panic: runtime error: slice bounds out of range

goroutine 1 [running, locked to thread]:
main.(*Creature).EquipItem(0xc000070000, 0xc00006e000, 0x0, 0xc00007dc48, 0x0, 0xc00007dc48)
        D:/Programowanie/golang/projects/src/RAWIG/monsters.go:234 +0x3f1
main.(*Creature).HandleEquippables(0xc000070000, 0xc000006028, 0x1, 0x1, 0x0, 0x0, 0x1)
        D:/Programowanie/golang/projects/src/RAWIG/player.go:281 +0x64
main.(*Creature).EquippablesMenu(0xc000070000, 0x0, 0xc00007dcf0)
        D:/Programowanie/golang/projects/src/RAWIG/player.go:271 +0x101
main.(*Creature).HandleEquipment(0xc000070000, 0xc00007df10, 0x0, 0xb)
        D:/Programowanie/golang/projects/src/RAWIG/player.go:200 +0x8c
main.(*Creature).EquipmentMenu(0xc000070000, 0xc00007df10, 0x462e90)
        D:/Programowanie/golang/projects/src/RAWIG/player.go:183 +0xbf
main.Controls(0x8, 0xc000070000, 0xc000072000, 0x1e, 0x1e, 0xc00007ded0, 0x2, 0x2, 0xc00007df10, 0x4f1f00)
        D:/Programowanie/golang/projects/src/RAWIG/controls.go:50 +0xbb
main.main()
        D:/Programowanie/golang/projects/src/RAWIG/main.go:63 +0x788
01:22:35.731 [error] Failed to unbind OpenGL context (A device attached to the system is not functioning)
VedVid commented 5 years ago

In utilities_math:
Changing range to "normal" iteration didn't help.
Dereferencing items didn't help.

VedVid commented 5 years ago

But - it's interesting. It looks like that it doesn't crash automatically. Maybe after equipping, menu stays (but it should not), and pressing key again is the source of crash?

VedVid commented 5 years ago

I can confirm that, after exiting menu after first try, weapon is equipped and is removed from inventory. So, the problem is remaing menu and therefore possibility of wrong input.

VedVid commented 5 years ago

PrintMenu is executed at the end and remains here, and I'm not sure why.

Current flow is, after dequipping weapon:

EquippablesMenu PrintEquippables PrintMenu (...so, we are calling equippables menu, that - via prin equippables - prepares data, then passes it to print menu. game waits for player input) HandleEquippables (handles player input, calls \/) EquipItem (so, item is equipped; now, game should go back to previous menu...) PrintEquippables (and it's true, it prints equippables again; but data for printing remains the same, while slice changed) PrintMenu (menu with equippables is printed)

VedVid commented 5 years ago

Latest affected commit: b947ef24e5affe7fcb6604f90e19e5b919c7ffcb

VedVid commented 5 years ago

Fixed in d2db8bcd433ae100540dd31ec1d5d946de7e4946 by adding missing "break" statement