это класс, который я хочу вставить. у него есть конструктор, инициализирующий m_bitmap. Фактически, инициализация m_bitmap не вызывает проблем. Я вставил для деталей.
#pragma once
#include "D2DApp.h"
class Image
{
public:
ComPtr<ID2D1Bitmap> m_bitmap;
Image(LPCWSTR filePath);
};
и это Конструктор
Image::Image(LPCWSTR filePath)
{
//Create Decoder
ComPtr<IWICBitmapDecoder> bitmapDecoder;
ThrowIfFailed(
D2DApp::GetApp()->
GetWicFactory()->CreateDecoderFromFilename(
filePath,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
bitmapDecoder.GetAddressOf()
)
);
//Get the current frame
ComPtr<IWICBitmapFrameDecode> frame;
ThrowIfFailed(
bitmapDecoder->GetFrame(0, frame.GetAddressOf())
);
//Create the format converter
ComPtr<IWICFormatConverter> wicImage;
ThrowIfFailed(
D2DApp::GetApp()->GetWicFactory()->CreateFormatConverter(
wicImage.GetAddressOf()
)
);
//Initialize wic Image
ThrowIfFailed(
wicImage->Initialize(
frame.Get(),
GUID_WICPixelFormat32bppPBGRA,
WICBitmapDitherTypeNone,
nullptr,
0,
WICBitmapPaletteTypeCustom
)
);
//Initialize D2d image
ThrowIfFailed(
D2DApp::GetApp()->GetD2DContext()->
CreateBitmapFromWicBitmap(
wicImage.Get(),
m_bitmap.ReleaseAndGetAddressOf()
)
);
}
, затем я вставляю его в контейнер карты
#include "Image.h"
#include <map>
class ImageSystem
{
private:
map<string, Image*> ImageData;
public:
void addData(string key, LPCWSTR filePath);
ComPtr<ID2D1Bitmap> GetData(string key);
~ImageSystem();
};
здесь возникает проблема, обе две строки кода не работал по той же причине.
Выброшено исключение: нарушение прав доступа на чтение. _Scary был nullptr.
void ImageSystem::addData(string key, LPCWSTR filePath)
{
//ImageData.insert(make_pair(key, new Image(filePath)));
ImageData[key] = new Image(filePath);
}