{"record":{"id":"23d3d36db1d0be8b","repo":"Unity-Technologies/UnityCsReference","slug":"localstart-has-to-be-positive","errorCode":null,"errorMessage":"localStart has to be positive","messagePattern":"localStart has to be positive","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Audio/StreamedAudioClipPreview.cs","lineNumber":61,"sourceCode":"            public double normalizedDuration;\n            public double normalizedStart;\n            public double deltaStep;\n            public AudioClip clip;\n            public int previewPixelsToRender;\n            public double localStart;\n            public double localLength;\n            public bool looping;\n\n            public ClipPreviewDetails(AudioClip clip, bool isLooping, int size, double localStart, double localLength)\n            {\n                if (size < 2)\n                    throw new ArgumentException(\"Size has to be larger than 1\");\n\n                if (localLength <= 0)\n                    throw new ArgumentException(\"length has to be longer than zero\", \"localLength\");\n\n                if (localStart < 0)\n                    throw new ArgumentException(\"localStart has to be positive\", \"localStart\");\n\n                if (clip == null)\n                    throw new ArgumentNullException(\"clip\");\n\n                this.clip = clip;\n\n                preview = AudioClipMinMaxOverview.GetOverviewFor(clip);\n\n                if (preview == null)\n                    throw new ArgumentException(\"Clip \" + clip + \"'s overview preview is null\");\n\n                looping = isLooping;\n\n                this.localStart = localStart;\n                this.localLength = localLength;\n\n                if (looping)\n                {","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Audio/StreamedAudioClipPreview.cs#L43-L79","documentation":"ArgumentException thrown by the ClipPreviewDetails constructor when localStart is negative. localStart represents the starting position within the AudioClip (in normalized time); a negative value would point before the clip's beginning and produce an invalid preview region.","triggerScenarios":"Constructing ClipPreviewDetails with a localStart value below zero. Occurs when a trim offset or loop start position is set to a negative value, or when floating-point arithmetic on normalized positions underflows below zero.","commonSituations":"Loop or trim UI controls that allow negative start values without clamping, serialized properties with incorrect default values, arithmetic errors when converting sample offsets to normalized time, animation or scrubber interactions that compute positions outside the valid range.","solutions":["Clamp localStart to a minimum of 0 before constructing ClipPreviewDetails.","Validate UI inputs for trim/loop start positions to disallow negative values.","Use Mathf.Clamp(localStart, 0, 1) to ensure the value is within the clip's normalized range.","Log the computed localStart when the error occurs to trace the calculation producing the negative value."],"exampleFix":"// before\nvar details = new ClipPreviewDetails(clip, looping, size, localStart, length);\n// after\ndouble safeStart = Math.Max(0, localStart);\nvar details = new ClipPreviewDetails(clip, looping, size, safeStart, length);","handlingStrategy":"validation","validationCode":"// Clamp localStart to minimum 0 before constructing ClipPreviewDetails\ndouble safeStart = Math.Max(0, localStart);\nvar details = new ClipPreviewDetails(clip, looping, size, safeStart, localLength);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp localStart to [0, 1] range for normalized clip positions.","Validate UI controls for trim/loop start to disallow negative values.","Use Mathf.Clamp on scrubber and timeline positions.","Log computed localStart values during debugging to trace negative-value sources."],"tags":["audio","editor","validation","argument-validation","preview","waveform"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}