Skip to content

Conversation

@n1lordduck
Copy link
Contributor

When a debugger is attached to a CPU entity, removing the entity does not currently detach the debugger. As a result, the debugger remains attached to a non-existent CPU, which can be confusing.

This PR ensures the debugger is properly detached when the CPU entity is removed, also creates a DetachDebugger method that removes the giant chunk of code in the original AttachDebugger method that was responsible for detaching it manually.

Copy link
Member

@DerelictDrone DerelictDrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, but in my testing detaching manually (by pressing R with the cpu tool) reports the detach message twice.
image (first detached with no attached debugger, second attached, then detaching will produce two messages)

This is due to a second net send for invalidating the debugger within the stool's own file, present here:

if player:KeyDown(IN_SPEED) then
if (trace.Entity:IsValid()) and
(trace.Entity:GetClass() == "gmod_wire_cpu") then
trace.Entity:SetMemoryModel(self:GetClientInfo("memorymodel"),self:GetClientInfo("customram"),self:GetClientInfo("customrom"))
trace.Entity:FlashData({})
net.Start("CPULib.InvalidateDebugger") net.WriteUInt(0,2) net.Send(player)
end
else
if (not trace.Entity:IsPlayer()) and
(trace.Entity:IsValid()) and
(trace.Entity:GetClass() == "gmod_wire_cpu") then
CPULib.AttachDebugger(trace.Entity,player)
CPULib.SendDebugData(trace.Entity.VM,nil,player)
net.Start("CPULib.InvalidateDebugger") net.WriteUInt(2,2) net.Send(player)
else
CPULib.AttachDebugger(nil,player)
net.Start("CPULib.InvalidateDebugger") net.WriteUInt(1,2) net.Send(player)
end
end
return true
end

Once resolved, this should be ready for merge tomorrow.

@n1lordduck
Copy link
Contributor Author

I believe I've fixed it!

Copy link
Member

@DerelictDrone DerelictDrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to clear this flag and on remove hook during detach if possible, as deleting the CPU after detaching your debugger reports that it was detached(again), after that we should be good assuming nothing else crops up
https://github.com/wiremod/wire-cpu/pull/73/files#diff-7ef44bc4870f2b9b65b05f458388a300de8f00377bfa7430d5e5b7e5026ce3b7R617-R623

@n1lordduck
Copy link
Contributor Author

Working on it

@n1lordduck
Copy link
Contributor Author

I hope everthing is correct now.

Copy link
Member

@DerelictDrone DerelictDrone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and working as intended.

@DerelictDrone DerelictDrone merged commit b3ef3ce into wiremod:master Dec 31, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants