Skip to content

Commit 27d2623

Browse files
committed
fix: 432 null pointer when removing probes (#433)
* Fixes native collection error * Made the error a warning and then deleted the warning
1 parent d05a058 commit 27d2623

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

Assets/Scripts/EphysLink/CommunicationManager.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,15 @@ public void GetPos(string manipulatorId, Action<Vector4> onSuccessCallback,
245245
{
246246
if (data.error == "")
247247
{
248-
onSuccessCallback(new Vector4(data.position[0], data.position[1], data.position[2],
249-
data.position[3]));
248+
try
249+
{
250+
onSuccessCallback?.Invoke(new Vector4(data.position[0], data.position[1], data.position[2],
251+
data.position[3]));
252+
}
253+
catch (Exception e)
254+
{
255+
onErrorCallback?.Invoke(e.ToString());
256+
}
250257
}
251258
else
252259
{

Assets/Scripts/TrajectoryPlanner/Probes/ManipulatorBehaviorController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class ManipulatorBehaviorController : MonoBehaviour
2121

2222
private void EchoPosition(Vector4 pos)
2323
{
24-
if (_probeController == null && !enabled) return;
24+
if (!enabled && _probeController == null) return;
2525
// Calculate last used direction for dropping to brain surface (between depth and DV)
2626
var dvDelta = Math.Abs(pos.z - _lastManipulatorPosition.z);
2727
var depthDelta = Math.Abs(pos.w - _lastManipulatorPosition.w);

Assets/Scripts/TrajectoryPlanner/Probes/ProbeManager.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public bool IsEphysLinkControlled
112112
private set
113113
{
114114
ManipulatorBehaviorController.enabled = value;
115+
print("MBC enabled: "+ManipulatorBehaviorController.enabled);
115116
EphysLinkControlChangeEvent.Invoke();
116117
EphysLinkControlledProbesChangedEvent.Invoke(Instances.Where(manager => manager.IsEphysLinkControlled).ToHashSet());
117118
}
@@ -209,16 +210,15 @@ private void Start()
209210
/// </summary>
210211
public void Destroy()
211212
{
212-
213213
ProbeProperties.ReturnColor(Color);
214214

215215
ColliderManager.RemoveProbeColliderInstances(_probeColliders);
216216

217217
// Force disable Ephys Link
218218
if (IsEphysLinkControlled)
219219
{
220-
CommunicationManager.Instance.UnregisterManipulator(ManipulatorBehaviorController.ManipulatorID);
221220
IsEphysLinkControlled = false;
221+
CommunicationManager.Instance.UnregisterManipulator(ManipulatorBehaviorController.ManipulatorID);
222222
}
223223

224224
// Delete this gameObject
@@ -228,10 +228,18 @@ public void Destroy()
228228

229229
private void OnDestroy()
230230
{
231+
// Destroy instance
231232
Debug.Log($"Destroying probe: {name}");
232233

233-
Instances.Remove(this);
234-
ProbeInsertion.Instances.Remove(ProbeController.Insertion);
234+
if (ProbeInsertion.Instances.Count == 1)
235+
ProbeInsertion.Instances.Clear();
236+
else
237+
ProbeInsertion.Instances.Remove(ProbeController.Insertion);
238+
239+
if (Instances.Count == 1)
240+
Instances.Clear();
241+
else
242+
Instances.Remove(this);
235243
}
236244

237245
private void OnEnable() => Instances.Add(this);

0 commit comments

Comments
 (0)