Deleting Sprite [SOLVED]

Started by Vincent, Fri 13/02/2015 10:18:06

Previous topic - Next topic

Vincent

Hello guys,

I don't know where to write this thought so I will write down here below...
I think some of you will feel bored reading this and I'm feel sorry already.

When we generate a DynamicSprite by
1° - DynamicSprite.CreateFromFile(string filename)
2° - DynamicSprite.CreateFromScreenShot(optional int width, optional int height)
3° - Etc etc

This command loads an extra sprite into memory which is not controlled by the normal AGS sprite cache and will not be automatically disposed of. Therefore, when you are finished with the image you MUST call Delete on it to free its memory

DynamicSprite.Delete();
You do not normally need to delete sprites, since the AGS Sprite Cache manages loading and deleting sprites automatically.
However, when an extra sprite has been loaded into the game then AGS does not delete it automatically, and you must call this command instead.


So I generate a DynamicSprite inside a room and I have also a button that quit the game.
(Yes, I think some of you have already figured out what I'm about to say)
But when i quit the game,
Ags create for me a textual warning by saying that the DynamicSprite has never deleted.
I have something like this (and actually doesn't solve the problem)
Code: ags

function btnQuitGame_Click(GUIControl *control, MouseButton button) 
{
  if (MyDynamicSprite != null) 
  {
    MyDynamicSprite.Delete();
    // MyDynamicSprite = null (?)
   }
  QuitGame(0);
}



How do you guys generally solve this kind of error ?
Any help is appreciated..

Ps: I don't have any module imported inside
(I'm running with 3.2.1)

However..
This is what I have
Code: ags

// MyDynamicSprite (Global variables)

function repeatedly_execute_always()
{

  ViewFrame *v = Game.GetViewFrame(player.View, player.Loop, player.Frame);
  int s = v.Graphic;

  MyDynamicSprite = DynamicSprite.CreateFromExistingSprite(s);
  oObject.Graphic = MyDynamicSprite.Graphic;

}



Ciao grazie :~(

Mandle

I would just turn off debugging mode before releasing the game as long as it's just a warning and doesn't actually cause any game errors/crashes...But that's just me...

A lot of warnings are just there to help warn of potential problems which might not actually develop into real problems: For example, trying to remove tint when no tint has been applied results in a warning message, but no bugs result in the game. It just meant that something non-existant was attempted to be removed...

Vincent

Ciao Mandle, thanks for answering.

Quote from: Mandle on Fri 13/02/2015 12:16:30
I would just turn off debugging mode before releasing the game

Oh.. I didn't thought that the debugging mode generate the textual warnings...
This is cute to know (still learning)

Before reading your message I tried to solve this error again..
And, I got it work by doing this.. (in debug mode)
Code: ags

function btnQuitGame_Click(GUIControl *control, MouseButton button) 
{
  int i = 0;
  while (i < 3)
  {
    if (MyDynamicSprite != null) MyDynamicSprite.Delete();
    i ++;
  }
  QuitGame(0);
}


But I got it work without message error then.. :-\
It's okay now, (i think)

SMF spam blocked by CleanTalk