2017-02-02 1 views
0

Je rencontre des problèmes lors de la création de bitmaps dans Direct2D. Chaque fois que j'utilise la fonction HWNDRenderTarget::DrawBitmap, j'obtiens des violations d'accès (code 0xc0000005). Voici la fonction en question.Violation d'accès (fonction Direct2D HWNDRenderTarget :: DrawBitmap())

void Graphics::game() { 

     mprendertarget->Clear(D2D1::ColorF(D2D1::ColorF::Black)); 
     if (rot > 360) { 
      rot = 0; 
     } 
     if (rot2 > 360) { 
      rot2 = 0; 
     } 
     if (GetKeyState(VK_LEFT)) { 
      rot--; 
     } 

     if (GetKeyState(VK_RIGHT)) { 
      rot++; 
     } 
     D2D1_RECT_F debugarenatextrect = {0.0f, 0.0f, 1000.0f, 6000.0f}; 
     mprendertarget->DrawTextA(P_GAME_DEBUG_ARENATEXT, wcslen(P_GAME_DEBUG_ARENATEXT), mpgenerictextformat, debugarenatextrect, mpsolidbrush, D2D1_DRAW_TEXT_OPTIONS_NONE, DWRITE_MEASURING_MODE_NATURAL); 

     const D2D1_RECT_F shipimagerect = RectF(0.0f,0.0f,29.0f,29.0f); 
     mprendertarget->SetTransform(D2D1::Matrix3x2F::Rotation(rot, D2D1::Point2F(29/2, 29/2))); 
     //Access Violation! V 
     mprendertarget->DrawBitmap(ship, RectF(0.f, 0.f, 29.f, 29.f), 1.0f, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, RectF(0.f, 0.f, 29.f, 29.f)); 
    } 

Idéalement, il est censé diminuer rot (rotation) lorsque la flèche gauche enfoncée et augmenter rot lorsque la touche flèche droite est enfoncée. Ensuite, il affiche une petite image (29x29) d'un navire, tourné rot degrés. P_GAME_DEBUG_ARENATEXT est une chaîne WCHAR * sans rapport avec le problème. mprendertarget est de type ID2D1HwndRenderTarget.

Répondre

0

Il s'avère qu'il y avait une fonction qui a réécrit l'image de navire à NULL. J'ai supprimé cela et il n'y a plus de violation d'accès.