From 0bcdf9884d735c0bc69b7986f98e0a89e454c9f8 Mon Sep 17 00:00:00 2001 From: freyers Date: Fri, 15 May 2026 22:30:42 +0000 Subject: [PATCH] fix(cluster): drop dead AkAlloca slot and reset per-frame state CreateOutputObject passed (AkAudioObject*)AkAlloca(sizeof(AkAudioObject*)) as its output slot: a miscopy of the SDK Particle Generator example. The alloca'd buffer is never used (the real slot is &newObject) and the value is overwritten by CreateOutputObjects before being read -- dead code, not active stack corruption. Use a nullptr slot, matching the SDK example and the ownership model GetOutputObjects already uses in ObjectClusterFX. performClustering never cleared sse_values (push_back'd every iteration of every audio frame): unbounded growth plus a stale-indexed convergence test. Clear it and assign labels so each run starts from clean state. --- ObjectCluster/SoundEnginePlugin/Kmeans.cpp | 3 ++- ObjectCluster/SoundEnginePlugin/Utilities.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ObjectCluster/SoundEnginePlugin/Kmeans.cpp b/ObjectCluster/SoundEnginePlugin/Kmeans.cpp index bc29768..ee4c882 100644 --- a/ObjectCluster/SoundEnginePlugin/Kmeans.cpp +++ b/ObjectCluster/SoundEnginePlugin/Kmeans.cpp @@ -351,7 +351,8 @@ void KMeans::setDistanceThreshold(float newValue) { } void KMeans::performClustering(const std::vector& objects, unsigned int max_iterations) { - labels.resize(objects.size(), -1); + sse_values.clear(); + labels.assign(objects.size(), -1); maxClusters = determineMaxClusters(objects.size()); initializeCentroids(objects); diff --git a/ObjectCluster/SoundEnginePlugin/Utilities.cpp b/ObjectCluster/SoundEnginePlugin/Utilities.cpp index 4d4dc1f..d775ec6 100644 --- a/ObjectCluster/SoundEnginePlugin/Utilities.cpp +++ b/ObjectCluster/SoundEnginePlugin/Utilities.cpp @@ -57,8 +57,8 @@ AkAudioObjectID Utilities::CreateOutputObject(const AkAudioObject* inobj, const { AkAudioObjectID outputObjKey = AK_INVALID_AUDIO_OBJECT_ID; AkUInt32 numObjsOut = 1; - // Allocate space for a new output object - AkAudioObject* newObject = (AkAudioObject*)AkAlloca(sizeof(AkAudioObject*)); + // CreateOutputObjects allocates the object and fills this slot + AkAudioObject* newObject = nullptr; AkAudioObjects outputObjects; outputObjects.uNumObjects = numObjsOut; outputObjects.ppObjectBuffers = nullptr;