Blender,Cycles Render,调用函数导致应用程序崩溃

时间:2018-01-02 10:35:41

标签: c++ crash blender renderer

我试图在Cycles渲染过程中获取每个样本的颜色。为此,我正在调用以下函数

void update_bcd_inputs(int x, int y, float sampleR, float sampleG, float sampleB){

    float current_valueR = sStats->m_meanImage.getValue(bcd::PixelPosition(x, y), 0); // += sampleR;
    float current_valueG = sStats->m_meanImage.getValue(bcd::PixelPosition(x, y), 1); // += sampleG;
    float current_valueB = sStats->m_meanImage.getValue(bcd::PixelPosition(x, y), 2); // += sampleB;
    sStats->m_meanImage.set(x, y, 0, current_valueR + sampleR);
    sStats->m_meanImage.set(x, y, 1, current_valueG + sampleG);
    sStats->m_meanImage.set(x, y, 2, current_valueB + sampleB);
}

在blender / intern / cycles / device / device_cpu.cpp

void path_trace(DeviceTask &task, RenderTile &tile, KernelGlobals *kg)
{
    float *render_buffer = (float*)tile.buffer;
    int start_sample = tile.start_sample;
    int end_sample = tile.start_sample + tile.num_samples;
    float inv_weight = 1.0f/tile.num_samples;

    for(int sample = start_sample; sample < end_sample; sample++) {
        if(task.get_cancel() || task_pool.canceled()) {
            if(task.need_finish_queue == false)
                break;
        }

        for(int y = tile.y; y < tile.y + tile.h; y++) {
            for(int x = tile.x; x < tile.x + tile.w; x++) {
                path_trace_kernel()(kg, render_buffer,
                                    sample, x, y, tile.offset, tile.stride);

                int step = tile.offset + x + y*tile.stride;
                step *= kernel_data.film.pass_stride;
                float sampleR = *(render_buffer +step);
                float sampleG = *(render_buffer +step +1);
                float sampleB = *(render_buffer +step +2);
                update_bcd_inputs(x, y, sampleR*inv_weight, sampleG*inv_weight, sampleB*inv_weight);
            }
        }

        tile.sample = sample + 1;

        task.update_progress(&tile, tile.w*tile.h);
    }
}

SamplesStatisticsImages sStats是CPUDevice的一个属性

struct SamplesStatisticsImages
{
    SamplesStatisticsImages() = default;
    SamplesStatisticsImages(int i_width, int i_height, int i_nbOfBins);
    SamplesStatisticsImages(const SamplesStatisticsImages&) = default;
    SamplesStatisticsImages(SamplesStatisticsImages&&) = default;
    SamplesStatisticsImages& operator=(const SamplesStatisticsImages&) = default;
    SamplesStatisticsImages& operator=(SamplesStatisticsImages&&) = default;

    DeepImage<float> m_nbOfSamplesImage;
    DeepImage<float> m_meanImage;
    DeepImage<float> m_covarImage;
    DeepImage<float> m_histoImage;
};

以下是文件DeepImage.hppDeepImage.h

问题是对update_bcd_inputs的调用使Blender崩溃,甚至没有尝试渲染图像。我只是将渲染器更改为Cycles,尝试添加新材料和繁荣,它会崩溃。

我发现问题是设置功能(当我删除它时,应用程序不会崩溃)。

有人能理解为什么吗?我没有很强的C ++技能,所以我必须遗漏一些东西。

这也是crash log

谢谢!

修改:更精确

以下是修改后的device_cpu.cpp

sStats指针在CPUDevice构造函数中用nullptr初始化

CPUDevice(DeviceInfo& info_, Stats &stats_, bool background_)
: Device(info_, stats_, background_),
  texture_info(this, "__texture_info", MEM_TEXTURE),
  histoParams(),
#define REGISTER_KERNEL(name) name ## _kernel(KERNEL_FUNCTIONS(name))
  ...
#undef REGISTER_KERNEL
{
    ...
    sStats = nullptr;
}

然后分配到

void thread_render(DeviceTask& task)
{
   ...
   sStats = new bcd::SamplesStatisticsImages(task.w, task.h, histoParams.m_nbOfBins);
   ...
}

histoParams也是CPUDevice的一个属性。

struct HistogramParameters
{
    HistogramParameters() :
            m_nbOfBins(20),
            m_gamma(2.2f),
            m_maxValue(2.5f) {}

    int m_nbOfBins;
    float m_gamma; ///< exponent for the exponential size increase of histogram bins
    float m_maxValue;
};

0 个答案:

没有答案