{"record":{"id":"8c592780e7bdb03f","repo":"ppy/osu","slug":"a-nameof-poolableskinnablesample-cannot-be-appl","errorCode":null,"errorMessage":"A {nameof(PoolableSkinnableSample)} cannot be applied multiple {nameof(ISampleInfo)}s.","messagePattern":"A (.+?) cannot be applied multiple (.+?)s\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"osu.Game/Skinning/PoolableSkinnableSample.cs","lineNumber":62,"sourceCode":"        /// Creates a new <see cref=\"PoolableSkinnableSample\"/> with an applied <see cref=\"ISampleInfo\"/>.\r\n        /// </summary>\r\n        /// <param name=\"sampleInfo\">The <see cref=\"ISampleInfo\"/> to attach.</param>\r\n        public PoolableSkinnableSample(ISampleInfo sampleInfo)\r\n            : this()\r\n        {\r\n            Apply(sampleInfo);\r\n        }\r\n\r\n        /// <summary>\r\n        /// Applies an <see cref=\"ISampleInfo\"/> that describes the sample to retrieve.\r\n        /// Only one <see cref=\"ISampleInfo\"/> can ever be applied to a <see cref=\"PoolableSkinnableSample\"/>.\r\n        /// </summary>\r\n        /// <param name=\"sampleInfo\">The <see cref=\"ISampleInfo\"/> to apply.</param>\r\n        /// <exception cref=\"InvalidOperationException\">If an <see cref=\"ISampleInfo\"/> has already been applied to this <see cref=\"PoolableSkinnableSample\"/>.</exception>\r\n        public void Apply(ISampleInfo sampleInfo)\r\n        {\r\n            if (this.sampleInfo != null)\r\n                throw new InvalidOperationException($\"A {nameof(PoolableSkinnableSample)} cannot be applied multiple {nameof(ISampleInfo)}s.\");\r\n\r\n            this.sampleInfo = sampleInfo;\r\n\r\n            Volume.Value = sampleInfo.Volume / 100.0;\r\n\r\n            if (LoadState >= LoadState.Ready)\r\n                updateSample();\r\n        }\r\n\r\n        protected override void SkinChanged(ISkinSource skin)\r\n        {\r\n            base.SkinChanged(skin);\r\n            updateSample();\r\n        }\r\n\r\n        /// <summary>\r\n        /// Whether this sample was playing before a skin source change.\r\n        /// </summary>\r","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/ppy/osu/blob/d9c73e12adff2feaae4a3e158d36fe5883faf6ca/osu.Game/Skinning/PoolableSkinnableSample.cs#L44-L80","documentation":"Thrown by PoolableSkinnableSample.Apply(ISampleInfo) when sampleInfo is already non-null, enforcing that a pooled sample is single-use: exactly one ISampleInfo may ever be applied during its lifetime. Re-applying would leave stale volume/sample state.","triggerScenarios":"Calling Apply(sampleInfo) twice on the same PoolableSkinnableSample instance without returning it to the pool (or before it was reset) — the second Apply hits the guard.","commonSituations":"Pooling bug where a sample is not properly returned/reset before reuse; calling Apply in a loop without pooling discipline; holding a reference to a pooled sample and reusing it across plays.","solutions":["Return the sample to the pool (or dispose/recreate) before applying a new ISampleInfo.","Ensure the pool resets sampleInfo to null on return; do not retain the instance across reuses.","Use a fresh PoolableSkinnableSample per playback if pooling is unnecessary.","Audit Apply call sites to confirm each is preceded by a pool Get (not a retained instance)."],"exampleFix":"// before\nsample.Apply(infoA);\nsample.Apply(infoB); // throws\n\n// after\nsample.Apply(infoA);\npool.Return(sample);\nsample = pool.Get();\nsample.Apply(infoB);","handlingStrategy":"validation","validationCode":"if (sample.HasApplied)\n    throw new InvalidOperationException(\"Sample already applied; return to pool first.\");","typeGuard":null,"tryCatchPattern":"try { sample.Apply(info); }\ncatch (InvalidOperationException) { sample = pool.Get(); sample.Apply(info); }","preventionTips":["Return PoolableSkinnableSample to the pool before re-Apply.","Ensure pool reset clears sampleInfo.","Use one sample instance per playback."],"tags":["skinning","audio","sample","pooling","api-misuse"],"backgroundTag":null,"analyzedSha":"d9c73e12adff2feaae4a3e158d36fe5883faf6ca","analyzedAt":"2026-08-13T14:12:54.015Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}