Note that there are some explanatory texts on larger screens.

plurals
  1. POSDL_Surface disappears after game runs for several minutes?
    primarykey
    data
    text
    <p>after running my asteroids game for several minutes the SDL_Surface representing my ship disappears. Somehow the surface that holds the rotated image (rot) of the ship is getting set to NULL. I can't figure out why! Before I added the line <code>if(rot != NULL &amp;&amp; image != NULL)</code> the program would crash after running for a about a minute an thirty seconds, but now the image just disappears. I can't seem to figure out whats wrong! Thanks in advance!</p> <p>Sprite Class functions involving rotation and rendering.</p> <pre><code>void Sprite::Rotate(double angleAdd) { rotated = true; double temp = 0; angle += angleAdd; temp = angleAdd + angle; if (temp &gt;= 360) angleAdd = temp - 360; if (temp &lt;= 360) angleAdd = temp + 360; rot = rotozoomSurface(image, angle , 1.0, 1); } void Sprite::Draw(SDL_Surface* screen) { if(image == NULL) SDL_FillRect(screen, &amp;rect, color); else { if (rotated) { rotRect.x = x; rotRect.y = y; //Center the image if(rot != NULL &amp;&amp; image != NULL){ rotRect.x -= ((rot-&gt;w/2) - (image-&gt;w/2)); rotRect.y -= ((rot-&gt;h/2) - (image-&gt;h/2)); } SDL_BlitSurface(rot, NULL, screen, &amp;rotRect); } else SDL_BlitSurface(image, NULL, screen, &amp;rect); } } bool Sprite::SetImage(std::string fileName) { imageFileName = fileName; SDL_Surface* loadedImage = NULL; loadedImage = SDL_LoadBMP(fileName.c_str()); if(loadedImage == NULL) { if (debugEnabled) printf("Failed to load image: %s\n", fileName.c_str()); SDL_FreeSurface(loadedImage); return false; } else { image = SDL_DisplayFormat(loadedImage); SDL_FreeSurface(loadedImage); return true; } } </code></pre> <p>Main:</p> <pre><code> if (arrowPressed[0]) { ship.SetImage(shipFor.GetImage()); if(!phase) ship.Accel(-moveSpeed); else ship.Accel(-moveSpeed * 2); } if (arrowPressed[1]) { ship.Rotate(turnSpeed); ship.SetImage(shipRig.GetImage()); } if (arrowPressed[3]) { ship.Rotate(-turnSpeed); ship.SetImage(shipLef.GetImage()); } if (arrowPressed[0] &amp;&amp; arrowPressed[1]) ship.SetImage(shipForRig.GetImage()); if (arrowPressed[0] &amp;&amp; arrowPressed[3]) ship.SetImage(shipForLef.GetImage()); if (!arrowPressed[0] &amp;&amp; !arrowPressed[1] &amp;&amp; !arrowPressed[3]) ship.SetImage(shipNor.GetImage()); if (ship.GetCenterX() &gt;= RESX - 40) ship.SetPosCentered(50, ship.GetCenterY()); if (ship.GetCenterX() &lt;= 40) ship.SetPosCentered(RESX - 50, ship.GetCenterY()); if (ship.GetCenterY() &gt;= RESY - 40) ship.SetPosCentered(ship.GetCenterX(), 50); if (ship.GetCenterY() &lt;= 40) ship.SetPosCentered(ship.GetCenterX(), RESY - 150); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload