Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Old Guy on Mon 22/12/2008 21:26:26

Title: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Mon 22/12/2008 21:26:26
I am experiencing a sporadic error attempting to create a dynamic sprite from a screenshot. The screenshot is displayed as a thumbnail on my Save Game GUI.

I am using:
AGS 3.1.0.60
Windows 2000 SP4

I am merrily tripping along testing my game using the debugger, and saving my game several times along the way. Out of the blue, when I click the Save Game button on the Iconbar, which normally brings up my Save Game GUI, I receive the following error message:

AGS had a problem running your game. The error can be seen below, and is most likely due to a scripting problem. The line in the script where this occurred is highlighted for you.

     DeleteSprite: Attempted to free a static sprite that was not loaded by the script.

The line in the global script that is highlighted as the cause of the error is as follows:

     Screenshot = DynamicSprite.CreateFromScreenShot(70, 52);

The “Screenshot” variable is used display a thumbnail of the current room on the Save Game GUI, and has been defined at the top of the global script as follows:

     DynamicSprite *Screenshot;


1) When I run the game again, load the most recent saved game, and then click the Save Game button on the Iconbar, the Save Game GUI is displayed. However, the thumbnail displayed on the GUI is not a screenshot of the current room, but is instead the Blue Cup!!!

2) If I now hit the cancel button on the Save Game GUI, and once again press the Save Game button on the Iconbar, the error described above happens once again.

3) If I restart the game, and load any saved game except the most recent one, everything works normally, and I can go on to successfully created additional saved games that do not exhibit any problems.

4) To see if I could reproduce the error, I removed all the saved games from the saved games directory, started the game from the beginning, began testing the game once again, and saving games along the way. Sure enough, at some point I once again experienced the same problem described above.
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Pumaman on Mon 22/12/2008 22:38:56
Can you post the script that is involved in saving the game?
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Tue 23/12/2008 06:41:06
Quote from: Pumaman on Mon 22/12/2008 22:38:56
Can you post the script that is involved in saving the game?

At the top of the global script we have ...

     int Slot = 0;
     DynamicSprite *Screenshot;
     DynamicSprite *SavedGameScreenshot;


The following script is executed when you press the F5 key, or on the Iconbar, you click the Save button. The “Screenshot =” line is the one that is sometimes flagged as an error ...

     //*---------------------------------------------*
     // Prepare and display the Save Panel *
     //*---------------------------------------------*
     function PrepareSavePanel()
     {
     gIconbar.Visible = false;
     mouse.Visible = false;
     Wait(1);
     Screenshot = DynamicSprite.CreateFromScreenShot(70, 52);
     Wait(1);
     mouse.Visible = true;
     gSavePanel.Visible = true;
     tSavePanel_Name.Text = "";
     tSavePanel_List.FillSaveGameList();
     mouse.Mode = eModeInteract;
     mouse.UseModeGraphic(eModePointer);
     }


The following script is executed when on the Save Game GUI, you click the Save button or press enter ...

     //*----------------------------*
     // Handle saving a game *
     //*----------------------------*
     function SaveGame()
     {
     if (tSavePanel_Name.Text == ""){
         Display("Please enter a name for the saved game.");
         return;}
     gSavePanel.Visible = false;
     mouse.Visible = false;
     Wait(1);
     SaveGameSlot(Slot, tSavePanel_Name.Text);
     Wait(1);
     mouse.Visible = true;
     gIconbar.Visible = true;
     mouse.UseDefaultGraphic();
     }


There is one other piece of script that may or may not be of interest.

When the Save Game GUI is visible, this script checks to see if the name being typed in the save game text box matches any of the names in the save game list box. The purpose of this script is to show the proper image for the thumbnail on the Save Game GUI, and to provide the proper slot number for the save.

If there is no match, then we must be doing a new saved game, and so we will set bSavePanel_Thumbnail.NormalGraphic to the screenshot that we took when the Save Game GUI was first displayed (see above). If there is a match, then we must be overwriting a previously saved game, and so we will set bSavePanel_Thumbnail.NormalGraphic to the screenshot associated with the previously saved game.

     //*------------------------------------------------------------------------*
     // Check for matching saved game name in saved game list *
     //*------------------------------------------------------------------------*
     function repeatedly_execute()
     {
     int x;
     if (gSavePanel.Visible == true){
         x = 0;
         Slot = tSavePanel_List.ItemCount;
         bSavePanel_Thumbnail.NormalGraphic = Screenshot.Graphic;   
         while (x < tSavePanel_List.ItemCount) {
             if (tSavePanel_Name.Text == tSavePanel_List.Items
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Tue 23/12/2008 07:18:59
In my last post, I see that for some reason two square blocks have been inserted into the original text.

I don't know why this has happened, but be advised ... wherever you see these square blocks, please substitute the following:

<LeftSquareBracket>x<RightSquareBracket>

In other words, the variable "x", is bracketed by a left and right square bracket.

Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: monkey0506 on Tue 23/12/2008 08:05:31
Just FYI you can include code in your posts by using [code] and [/code]:

// GlobalScript.asc
function do_something() {
  int array[5];
  int x = 0;
  while (x < 5) {
    array[x] = (x + 27) * (x - 27);
    x++;
  }
}


And you can trick the forum parser into posting tags as plain-text by using formatting...like this: [b][code[/b][b]][/code[/b][b]][/b] which would be printed out as:

[code][/code] ::)
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Pumaman on Tue 23/12/2008 17:47:48
Hmm, the script looks reasonable. Would you be able to upload a version of the game that demonstrates this problem?
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Mon 29/12/2008 03:44:09
Quote from: monkey_05_06 on Tue 23/12/2008 08:05:31
Just FYI you can include code in your posts by using [code] and [/code]:

Thanks for the tip!
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Mon 29/12/2008 03:46:25
Quote from: Pumaman on Tue 23/12/2008 17:47:48
Hmm, the script looks reasonable. Would you be able to upload a version of the game that demonstrates this problem?

I have uploaded the game and sent you a PM with the information needed to download the game.

Thanks for your assistance.
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Pumaman on Tue 30/12/2008 20:08:53
Thanks for uploading the game, and thanks for providing such detailed instructions on reproducing it.

I can reproduce the problem -- it looks like the dynamic sprite memory is corrupt in the latest three save games ("Cellar", "Visited 1968" and "Got Folder"). If you load any of these it will crash fairly quickly; the older four save games are fine.

So at some point between when you saved "Ball Machine 2" and when you saved "Got Folder", the game state got corrupted.
The problem is, at the moment I'm not sure why this happened or how to stop it happening again. Can you think if anything of note happened when you were playing between those points?

How long would it take to play through from the "Ball Machine 2" save to the point in the game where "Got Folder" is and see if the problem re-appears?
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Tue 30/12/2008 21:37:23
Quote from: Pumaman on Tue 30/12/2008 20:08:53
So at some point between when you saved "Ball Machine 2" and when you saved "Got Folder", the game state got corrupted.
The problem is, at the moment I'm not sure why this happened or how to stop it happening again. Can you think if anything of note happened when you were playing between those points?

How long would it take to play through from the "Ball Machine 2" save to the point in the game where "Got Folder" is and see if the problem re-appears?

Nothing of note happened along the way from "Ball Machine 2" to "Got Folder", and it was not until "Cellar" that the dreaded Blue Cup made its first appearance.

I will be happy to play from Ball Machine 2 and attempt to find the point at which things go bad again. Any suggestions as to any special debugging things I can do to help?

Thanks again.
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Pumaman on Tue 30/12/2008 23:09:18
Thanks for offering to help out with this.

Could you please do the following:

1. Make a backup copy of your game folder
2. Download AGS 3.1.1 from the website, and rebuild the game with that.
3. Give it a quick run to make sure the upgrade hasn't broken anything.
4. Download this: http://www.adventuregamestudio.co.uk/acwin.zip
5. Extract the acwin.exe file, and copy it into the folder where you installed the 3.1.1 editor. This will replace the 3.1.1 acwin.exe file that is already there.
6. Open the 3.1.1 editor, and run the game. Press Ctrl+V and verify that the version number is 3.12.1059.

Now, if you could play the game through again until you encounter the problem (unfortunately existing save games won't be compatible, you'll have to restart), that'd be great. This special build of AGS will create a warnings.log file in the game folder with lots of logging information (please check this file exists after playing for a couple of minutes!), which I can then use to try and track the problem down.

To maximize the chances of seeing the bug, regularly open the Save Game dialog and click on various games in the list, then cancel the dialog again.

Thanks!
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Wed 31/12/2008 20:45:42
Quote from: Pumaman on Tue 30/12/2008 23:09:18
Now, if you could play the game through again until you encounter the problem (unfortunately existing save games won't be compatible, you'll have to restart), that'd be great. This special build of AGS will create a warnings.log file in the game folder with lots of logging information (please check this file exists after playing for a couple of minutes!), which I can then use to try and track the problem down.

I will send you a PM with a download location for the most recent set of saved games, and the warnings.log file.
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Pumaman on Thu 01/01/2009 15:22:03
Thanks! I really appreciate all your help with this and all the detail you've been providing. Using your latest "Before Folder" save I have been able to track down the problem.

It's actually quite a serious DynamicSprite bug in AGS that looks like it affects all previous versions too.
Please could you do the following:
1. Download this: http://www.adventuregamestudio.co.uk/acwin.zip?newbuild
2. Extract the acwin.exe file, and copy it into the folder where you installed the 3.1.1 editor. This will replace the 3.1.1 acwin.exe file that is already there.
3. Open the 3.1.1 editor, and run the game. Press Ctrl+V and verify that the version number is 3.12.1061.

This version is compatible with the save games you created last time, and should fix the problem. Although the "Got folder" save is corrupted and will not work, if you load the "Before folder" save with this new AGS version the problem should no longer happen.

Please give this new version a try. I have left in the extra logging for now, just in case you still have problems.
If everything goes ok, I'll remove the logging and build this fix into AGS 3.1.2.

Thanks!
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Old Guy on Fri 02/01/2009 02:36:52
Quote from: Pumaman on Thu 01/01/2009 15:22:03
Please give this new version a try. I have left in the extra logging for now, just in case you still have problems.
If everything goes ok, I'll remove the logging and build this fix into AGS 3.1.2.

That seems to have fixed the problem. Nice job!

Over the next couple of days I will test the game from beginning to end a couple of times to make sure, but I think you can take this item off your list.

I am curious though ... what was the nature of the problem?

And thank you! I have always been amazed that one guy continues to support all of us out here with bug fixes, enhancements, and daily attention to the forum.

Hope the new year treats you well.
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Pumaman on Fri 02/01/2009 17:56:20
Quote from: Old Guy on Fri 02/01/2009 02:36:52
That seems to have fixed the problem. Nice job!

Glad to hear it! Do let me know if it rears its ugly head again.

QuoteI am curious though ... what was the nature of the problem?

AGS uses a sprite cache, which keeps the most recently used sprites in memory. When it needs to access a new sprite, it deletes an old one from memory that hasn't been used for a while.

This deletion from memory is only supposed to be done with standard sprites that are part of the game files and can be re-loaded from disk when needed -- but there was a bug where in certain situations it could delete DynamicSprites that you created in the script too.

QuoteAnd thank you! I have always been amazed that one guy continues to support all of us out here with bug fixes, enhancements, and daily attention to the forum.

It's always a pleasure, though I can't promise to pay daily attention to the forum ;)
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: EnterTheStory (aka tolworthy) on Sat 03/01/2009 11:29:12
Quote from: Pumaman on Fri 02/01/2009 17:56:20This deletion from memory is only supposed to be done with standard sprites that are part of the game files and can be re-loaded from disk when needed -- but there was a bug where in certain situations it could delete DynamicSprites that you created in the script too.

This thread has come at just the right time. Thanks!

I just started selling my game, and for the first time ever found this bug. It's Murphy's law - some bugs won't show up until people pay money. :) I'm using 2.72, and obvious it's been fixed since then, but it's nice to know what it was. I think I know where it happens in my game, and can work around it. For the record, SSH's Simple Snow module makes heavy use of dynamic sprites, and the crash I get is usually soon after a snow scene, with the same error message listed earlier in this thread.
Title: Re: BUG: Sporadic error attempting to create a dynamic sprite from a screenshot
Post by: Pumaman on Sat 03/01/2009 15:21:37
The bug is most likely to occur if you have a global DynamicSprite that exists for a long time.

In normal bits of script where you create a dynamic sprite, do some stuff with it, then delete it you should never see this problem.

But if you have global DynamicSprite variable that you create at some point and then try to use a while later, this bug could have cropped up and deleted it in the meantime.