draw.CameraTargets silently fails

Regarding camera assignment and the code example referenced here:
ALINE Documentation – Advanced Cameras

The example provided in the documentation allocates a new array every frame within Update. To optimize this, I switched to using a preallocated array (_CameraTargets) and simply update its first element each frame, like so:

_CameraTargets[0] = InputManager.Instance.CurrentCamera;

However, this change causes the assignment to draw.cameraTargets to silently fail. After the line:

draw.cameraTargets = _CameraTargets;

draw.cameraTargets remains null.

Here’s the full snippet for context:

_CameraTargets[0] = InputManager.Instance.CurrentCamera;

var draw = DrawingManager.GetBuilder(true);
draw.cameraTargets = _CameraTargets;
using (draw.WithMatrix(matrix))
using (draw.WithLineWidth(LineWidth, IsAutomaticJoinsEnabled))
{
    if (IsSolidEnabled)
        draw.SolidBox(LocalPosition, Quaternion.identity, 1.0f, FillColor);
    draw.WireBox(LocalPosition, Quaternion.identity, 1.0f, LineColor);
}
draw.Dispose();

Is there an internal check that prevents the cameraTargets assignment if the array is reused or modified externally? Or is there a required step to force the DrawingManager to recognize updated values in a persistent array?

Hi

I cannot see anything in the code that would cause that kind of issue.

Can you verify this? I see no way for this to happen. Verify that you are really setting something non-null to the property, and it then returns null.

The array must stay consistent until the end of the frame, though. No copy of it is made directly, and it is first checked when the cameras are rendered.

Hi Aron,

I’m retesting this morning and I can’t reproduce it. I’m using the same code shared above. I’m wondering if it is a bug in the editor showing the outline as a gizmo (when gizmos were turned off). I’ll keep watching this.

I have debugging logic in place to provide more information if it happens again.

_CameraTargets[0] = InputManager.Instance.CurrentCamera;

if (_CameraTargets[0] == null)
    Debug.LogError("source camera is null");

var draw = DrawingManager.GetBuilder(true);
draw.cameraTargets = _CameraTargets;

if (draw.cameraTargets == null || draw.cameraTargets[0] == null)
    Debug.LogError("destination camera is null");

using (draw.WithMatrix(matrix))
using (draw.WithLineWidth(LineWidth, IsAutomaticJoinsEnabled))
{
    if (IsSolidEnabled)
        draw.SolidBox(LocalPosition, Quaternion.identity, 1.0f, FillColor);
    draw.WireBox(LocalPosition, Quaternion.identity, 1.0f, LineColor);
}

draw.Dispose();
1 Like