directx — C ++ std :: make_unique & lt; & gt; Назначить классу Property

У меня есть простая операция, но мне сложно понять, что не так.

У меня есть частная собственность в моем заголовочном файле, например:

#pragma once
#include "Sprite.h"#include "MainMenuContent.h"
class MainMenu
{
public:
MainMenu();

void Initialize(ID3D11Device* device, ID3D11DeviceContext* context, int width, int height,
std::unique_ptr<Sol::Library::Content::UI::MainMenuContent> &content);

void Draw();

void OnDeviceLost();

~MainMenu();

private:
//...some other properties
std::unique_ptr<Sol::Library::Graphics::Sprite> m_title;
};

Я пытаюсь назначить его в методе инициализации следующим образом:

    void MainMenu::Initialize(ID3D11Device* device, ID3D11DeviceContext* context, int width, int height,
std::unique_ptr<MainMenuContent> &content)
{
//...some other code that seems to work ok

m_title = std::make_unique<Sol::Library::Graphics::Sprite>(); //<--this throws the error
}

Но я получаю ошибку:

Exception thrown: read access violation.
**std::_Unique_ptr_base<Sol::Library::Graphics::Sprite,std::default_delete<Sol::Library::Graphics::Sprite> >::_Myptr**(...) returned 0x8. occurred

Для справки, в конструкторе моего класса Sprite ничего нет, он объявлен в своем собственном заголовочном файле:

#pragma once

namespace Sol
{
namespace Library
{
namespace Graphics
{
class Sprite
{
public:
Sprite();

virtual void Update();
void Draw(std::unique_ptr<DirectX::SpriteBatch> &sb);

void OnDeviceLost();

~Sprite();

private:
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>    m_tex;
DirectX::SimpleMath::Vector2                        m_pos;
DirectX::SimpleMath::Vector2                        m_ori;
};
}
}
}

И определение класса Sprite:

#include "pch.h"#include "Sprite.h"
using namespace std;
using namespace DirectX;

namespace Sol
{
namespace Library
{
namespace Graphics
{
void Sprite::Update()
{

}

void Sprite::Draw(unique_ptr<SpriteBatch> &sb)
{
sb->Draw(m_tex.Get(), m_pos, nullptr, Colors::White, 0.f, m_ori);
}

void Sprite::OnDeviceLost()
{
m_tex.Reset();
}Sprite::~Sprite()
{
}
}
}
}

Любая помощь, которую вы, ребята, могли бы оказать, была бы очень признательна.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector