テクスチャの作成に失敗しました

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
alpha

テクスチャの作成に失敗しました

#1

投稿記事 by alpha » 8年前

画面にノイズを走らせるエフェクトを作ったのですが、ログに
テクスチャの作成に失敗しました
と出ています(動作には問題ない)
メモリ関連で不安が残りますので、質問させていただきます。

コード:

//noise.h
#pragma once
#include "Axis.h" //class Axis<T> はいわゆるPointや、VECTORと同じで、座標を保持するクラスです
#include <memory>

struct BoxElement;//矩形の情報を保持する構造体

class Noise
{
public:
//window:ウィンドウサイズが格納されている ScreenHandle:描画先グラフハンドル NoiseNum:描画するノイズの数
	Noise(const Axis<int> &window,const int ScreenHandle,unsigned int NoiseNum);
	virtual ~Noise();
	void NoiseCreate();//ノイズ作成
private:
	std:: unique_ptr<BoxElement[]> box_;
	const size_t kNoiseNum;//ノイズの数
	int noise_count_;
	const Axis<int>& kWindow;
	const int kScrHandle;
	const unsigned int kReductionRatio;
	void NoiseReset();//ノイズの矩形をリセット
};

コード:

#include "..\include\Noise.h"
#include <cmath>
#include "DxLib.h"
struct BoxElement{
	BoxElement(){}
	BoxElement(const Axis<int>& vertex1, const Axis<int>& vertex2) :
		vertex1_(vertex1),
		vertex2_(vertex2)
	{}
	~BoxElement(){}
	Axis<int> vertex1_;
	Axis<int> vertex2_;
};

Noise::Noise(const Axis<int> &window, const int ScreenHandle, unsigned int NoiseNum) :
kWindow(window),
kScrHandle(ScreenHandle),
kNoiseNum(NoiseNum),
kReductionRatio(4),
box_(new BoxElement[NoiseNum]())
{
	
	NoiseReset();
}


Noise::~Noise()
{
}

void Noise::NoiseCreate(){
	if (GetRand(1000) % 1000 == 0)//タイミング調整
	{
		noise_count_ = GetRand(40) + 20;
		NoiseReset();
	}
	if (noise_count_ > 0)
	{
		if (noise_count_-- % 6 == 1)
		{
			NoiseReset();
		}
		for (size_t i = 0; i < kNoiseNum; i++)
		{
			//ノイズをゆらゆらさせる
			int RandomSpeed = (((GetRand(8) % 4) > 2) * 2 - 1) * 2;
			box_[i].vertex1_.x_ += RandomSpeed;
			box_[i].vertex2_.x_ += RandomSpeed;

			//一度縮小してから拡大描画することで画像を歪ませる おそらくここらへんが問題
			int graph_handle = MakeScreen(static_cast<int>((box_[i].vertex2_.x_ - box_[i].vertex1_.x_)/kReductionRatio), static_cast<int>(( box_[i].vertex2_.y_ - box_[i].vertex1_.y_)/kReductionRatio));
			if (graph_handle != -1)
			{
				GraphFilterRectBlt(kScrHandle, graph_handle, box_[i].vertex1_.x_, box_[i].vertex1_.y_, box_[i].vertex2_.x_, box_[i].vertex2_.y_, 0, 0, DX_GRAPH_FILTER_DOWN_SCALE, kReductionRatio);
				DrawExtendGraph(box_[i].vertex1_.x_, box_[i].vertex1_.y_, box_[i].vertex2_.x_, box_[i].vertex2_.y_, graph_handle, FALSE);
				DeleteGraph(graph_handle);

			}
		}
	}
}
void Noise::NoiseReset(){
	for (size_t i = 0; i < kNoiseNum; i++)
	{
		Axis<int> vertex(GetRand(kWindow.x_), GetRand(kWindow.y_));
		box_[i] = BoxElement(Axis<int>(vertex.x_, vertex.y_), Axis<int>(vertex.x_ + GetRand(kWindow.x_ - vertex.x_), vertex.y_ + GetRand(kWindow.y_ - vertex.y_)));
	}
}
使用する際はNoiseCreateのみを呼び出します

“C言語何でも質問掲示板” へ戻る