简体   繁体   English

如何保留更改?

[英]How to have the changes stay?

I have MainScreen.cpp 我有MainScreen.cpp

void MainScreen::Show(D2DResources* pD2DResources)
{
    HRESULT hr = S_OK;

    ID2D1Bitmap* pBitmap=pD2DResources->GetpCurrentScreen();

    hr = pD2DResources->LoadBitmapFromFile(
        pD2DResources->GetpRT(),
        pD2DResources->GetpIWICIF(),
        L".\\Images\\MainScreen.jpg",
        0,
        0,
        &pBitmap
        );

    if(SUCCEEDED(hr))pD2DResources->DrawScreen();
}

and at some point the MainScreen::Show() function is called like this 并在某个时候像这样调用MainScreen :: Show()函数

MainScreen->Show(&d2DResources);

However, it seems that as pD2DResources calls DrawScreen() in the MainScreen::Show() function, whatever was stored into &pBitmap didn't save. 但是,似乎pD2DResources在MainScreen :: Show()函数中调用DrawScreen()时,存储在&pBitmap中的任何内容均未保存。 Actually, I get an unhandled exception and as it happens, pCurrentScreen, which should have received pBitmap's value, is 0x00000000. 实际上,我遇到了一个未处理的异常,碰巧它应该收到pBitmap的值pCurrentScreen为0x00000000。

What should I do? 我该怎么办?

As you know, LoadBitmapFromFile function failed 如您所知,LoadBitmapFromFile函数失败
So you should check LoadBitmapFromFile function's arguments 因此,您应该检查LoadBitmapFromFile函数的参数

However why did you assign pD2DResources->GetpCurrentScreen() to pBitmap?? 但是,为什么将pD2DResources-> GetpCurrentScreen()分配给pBitmap?
Next line, pBitmap will be assigned with LoadBitmapFromFile function again. 在下一行,将使用LoadBitmapFromFile函数再次分配pBitmap。

Additionally, If MainScreen's Show function called every frames, that is not efficient. 此外,如果MainScreen的Show函数调用每个帧,则效率不高。
Because you don't have to load bitmap every frames. 因为您不必每帧都加载位图。
And d2d bitmap should be released. 并应释放d2d位图。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM