简体   繁体   English

在发布模式下OpenAL Soft崩溃(调试工作正常)

[英]OpenAL Soft crashes in release mode (debug works fine)

I have created a small sample program in C++ trying to play sounds with OpenAL Soft. 我用C ++创建了一个小样本程序试图用OpenAL Soft播放声音。 The program crashes when compiled in release mode, when compiled in debug mode it works. 在发布模式下编译时程序崩溃,在调试模式下编译时可以正常工作。 I'm on OS X using 1.17.2. 我使用1.17.2在OS X上。

I get this error message: 我收到此错误消息:

SoundTest(28958,0x70000021d000) malloc: *** error for object 0x7fbdd26062c8: incorrect checksum for freed object - object was probably modified after being freed. SoundTest(28958,0x70000021d000)malloc:***对象0x7fbdd26062c8的错误:释放对象的校验和不正确 - 对象可能在被释放后被修改。

This is the full sample program: 这是完整的示例程序:

#include <iostream>
#include <AL/alc.h>
#include <AL/al.h>
#include <cmath>

using namespace std;

int main() {
    // Reset error state just to be sure
    alGetError();

    ALCdevice *device = alcOpenDevice(NULL);
    if (device == NULL) {
        cout << "Error creating device" << endl;
        return 1;
    }

    ALCcontext *context = alcCreateContext(device, NULL);
    if (!alcMakeContextCurrent(context)) {
        cout << "Failed to make context current" << endl;
        return 1;
    }

    ALuint buffer;

    // Set up sound buffer
    alGenBuffers((ALuint)1, &buffer);

    // Fill buffer with sine-wave
    float freq = 440.f;
    int seconds = 4;
    unsigned sample_rate = 22050;
    size_t buf_size = seconds * sample_rate;

    short *samples;
    samples = new short[buf_size];
    for(int i=0; i<buf_size; ++i) {
        samples[i] = (short) (32760 * sin((2.f * float(M_PI) * freq) / sample_rate * i ));
    }

    alBufferData(buffer, AL_FORMAT_MONO16, samples, buf_size, sample_rate);

    ALuint source;

    // Set up sound source
    alGenSources((ALuint)1, &source);
    alSourcef(source, AL_PITCH, 1);
    alSourcef(source, AL_GAIN, 1);
    alSource3f(source, AL_POSITION, 0, 0, 0);
    alSource3f(source, AL_VELOCITY, 0, 0, 0);
    alSourcei(source, AL_LOOPING, AL_FALSE);
    alSourcei(source, AL_BUFFER, buffer);

    // Start playing
    alSourcePlay(source);

    // Wait until the sound stops playing
    ALenum state;
    do {
        alGetSourcei(source, AL_SOURCE_STATE, &state);
    } while (state == AL_PLAYING);

    // Clean up
    alDeleteSources(1, &source);
    alcMakeContextCurrent(NULL);
    alcDestroyContext(context);
    alcCloseDevice(device);

    return 0;
}

If anyone else is having the same problem, have a look at this . 如果其他人遇到同样的问题,请看看这个 The issue is resolved now. 这个问题现在解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调试模式下未处理的异常,但在发行版中工作正常 - Unhandled exception in debug mode but works fine in release SFML 2.1程序在调试模式下运行良好,但在发布模式下崩溃 - SFML 2.1 program runs fine in debug mode, but crashes in release mode 自定义 memory 管理器在发布模式下工作正常,但在调试模式下无法正常工作 - Custom memory manager works fine in release mode, but not in debug mode 问答程序在发布版本时崩溃,在调试版本中运行良好 - Question and Answer program crashes on release build, works fine on debug build 为什么在发布模式下不能访问 for 循环,但在调试中它工作正常 - Why isn´t the for loop accessed in release mode, but in debug it works fine CImg在调试模式下引发异常,在Release中运行良好 - CImg throws an exception in Debug mode, works fine in Release 调试运行良好,但不在发布模式下 - Debug runs fine, but not in release mode 程序可以在Debug中正常运行,但不能在Release中正常运行 - Program works fine in Debug, but not in Release 在调试模式下访问冲突,但在发布模式下很好 - Access Violation in debug mode, but fine in release mode ActiveX控件在发布模式下崩溃,但在调试模式下不崩溃 - ActiveX control that crashes in release mode but not in debug mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM