Announcement

Collapse
No announcement yet.

Memmove causes access violation when trying to move raw pcm data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Memmove causes access violation when trying to move raw pcm data

    Hi all, I'm trying to load Wavs to memory as USoundWave pointers, I'm sporadically getting an access violation error on either the malloc call or the memmove,
    Code:
    0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
    So here's my load sample function:
    Code:
     void LoadSample(FString path) {
        if (FPaths::FileExists(path)) {
            TArray<uint8> rawSampleData = LoadRawFileData(path);
            samples.sampleData = NewObject<USoundWave>(USoundWave::StaticClass());
            if (samples.sampleData) {
                FWaveModInfo waveInfo;
                if (waveInfo.ReadWaveInfo(rawSampleData.GetData(), rawSampleData.Num())) {
                     int32 duration = *waveInfo.pChannels * *waveInfo.pBitsPerSample * *waveInfo.pSamplesPerSec;
                     if (duration) {
                        samples.sampleData->DecompressionType = EDecompressionType::DTYPE_RealTime;
                        samples.sampleData->SoundGroup = ESoundGroup::SOUNDGROUP_Default;
                        samples.sampleData->NumChannels = *waveInfo.pChannels;
                        samples.sampleData->Duration = *waveInfo.pWaveDataSize * 8.0f / duration;
                        samples.sampleData->RawPCMDataSize = waveInfo.SampleDataSize;
                        samples.sampleData->SetSampleRate(*waveInfo.pSamplesPerSec);
                        samples.sampleData->InvalidateCompressedData();
                        samples.sampleData->RawData.Lock(LOCK_READ_WRITE);
                        samples.sampleData->RawPCMData = (uint8*)FMemory::Malloc(samples.sampleData->RawPCMDataSize);
                        FMemory::Memmove(samples.sampleData->RawPCMData, rawSampleData.GetData(), rawSampleData.Num());
                        samples.sampleData->RawData.Unlock();
                     }
              }
        }
    }
    }
    and heres my LoadRawFileData() function:

    Code:
    TArray<uint8> LoadRawFileData(FString path) {
        TArray<uint8> results;
        FFileHelper::LoadFileToArray(results, *path);
        FMemoryReader memoryReader = FMemoryReader(results, true);
        return results;
    }
    So this is basically ripped from another example of this on there, but it never got resolved properly, so I'm not sure how I'd go about fixing it, just wondering if anything jumps out at anyone as being dumb, any help is really appreciated!!!
Working...
X