Skip to content

Commit

Permalink
Sanity checks for parent/child relationship bug I'm hunting
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Oct 26, 2022
1 parent 615be3a commit 9c98073
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modules/engine/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,9 @@ func (o *Object) childOf(parent *Object) {

func (o *Object) Adopt(child *Object) {
o.lock()
if o.hasChild(child) {
panic("can't adopt same child twice")
}
o.children = append(o.children, child)
o.unlock()

Expand All @@ -1045,6 +1048,9 @@ func (o *Object) Adopt(child *Object) {
}

func (o *Object) adopt(child *Object) {
if o.hasChild(child) {
panic("can't adopt same child twice")
}
o.children = append(o.children, child)

if child.parent != nil {
Expand All @@ -1053,6 +1059,15 @@ func (o *Object) adopt(child *Object) {
child.parent = o
}

func (o *Object) hasChild(child *Object) bool {
for _, ochild := range o.children {
if child == ochild {
return true
}
}
return false
}

func (o *Object) removeChild(child *Object) {
for i, curchild := range o.children {
if curchild == child {
Expand Down

0 comments on commit 9c98073

Please sign in to comment.