Game Development Community

iT2D 1.5 Preview 2 - GPF when changing scenes

by Craig Jorgensen · in iTorque 2D · 08/05/2011 (10:19 pm) · 6 replies

Build: 1.5 Preview 2, also occurs in 1.5 Preview 1
Platform: Windows XP
Target: Stand Alone (iTorque2DGame) on PC (Win32)

Issues: The game engine crashes (GPF) with
Unhandled exception at 0x00000043 in iTorque2DGame.exe: 0xC0000005: Access violation reading location 0x00000043.

Steps to Repeat:
I have made a sample project with some crappy image buttons that reproduces the problem consistantly.
Sample Code
To reproduce the problem from the sample project, just run the app and click the next and back buttons repeatedly to go between the two menu screens. It will randomly crash, sometime on the first click, sometimes it takes a few more.

Seems to be some sort of memory corruption as far as i can tell. Sometimes random mouse events get fired for other sprites that havent even been clicked on. The debugger always breaks attempting to process a mouse event, but it looks like the source object memory is possibly corrupt.

#1
08/06/2011 (8:21 am)
Before I download and run the project, do you have any errors or warnings in the console log?
#2
08/07/2011 (7:21 am)
The problem is that you are calling SceneWindow2D.loadLevel() from within a callback function.

I had the same problem, and it is easily fixed by using "schedule".

I posted the code here ---> How to Properly change Scenes in iTorque2D


What I assume is happening is: The resources for the current scene are being released about halfway through an update of that scene. Then when you load the next scene, it's resources take the place of the newly released resources, BUT the update method for the previous Level continues and is accessing memory that does not belong to it anymore.

I could be wrong but that is my first thought.

however, is this still a bug?
was it intended that we need to change levels "outside" of callback functions?
#3
08/07/2011 (9:21 pm)
I uploaded a new resource

Torque Minimal Template -- Part 5. Levels and sound

that possibly avoids this. It's a simpler way to change "levels".
#4
08/08/2011 (3:13 am)
Thanks guys, your help is much appreciated. Tried searching the forums for this problem, guess i was just using the wrong keywords because i didnt come across your post. Speaking of searching forums, is there a way to search a specific section only, eg just posts in the iTorque2D section?
#5
08/08/2011 (5:34 am)
@Pedro: I must say, your tutorials are REALLY well done and this part 5 with levels is a pretty good way to go about it, just correct me if I'm wrong but it looks like this method is only valid if you only create one Level in the TGB (Torque Game Builder), which would mean all of your assets are loaded on your first screen and stay loaded for the entire game, that and you cannot layout anything using the TGB (well you COULD, but it would get messy).

now don't get me wrong, I'm not saying its a bad choice, just it looks like it has its trade offs. it would be more efficient (BY FAR for the cpu) but if your working with an artist (like I am) then they (usually) want to be able to drag and drop the assets to make the scene look good, and not play with numbers.

Also if the OP already set up his game for the use of more than one TGB Level, then using my post would be incredibly faster to implement, really only one copy and paste and its going. whereas using that method might require a complete restructuring of their project.

BUT I believe I will use your new Level technique for my next game ;P. Also, like always, it is a very well done Tutorial, and I look forward to any future Tutorials that you create :)

@Craig: I'm not even sure if the searching feature on GarageGames forums even works correctly. I've tried searching for many posts and could not find anything relating to what I was searching for... but now that I tried to search just now, everything seemed to work fine? hahaha... it MAY have just gotten better?
#6
08/08/2011 (7:35 am)
@Craig

best search tool is in Google, type
site:garagegames.com "my search string"

@Daniel

Thanks. I do not use the TGB GUI Editor at all, I do everything by code. I am not totally sure about this, but I believe this function deletes the previous objects from the scene and loads new ones.

I made this function based on the several script calls provided by the "default" template, but did not had a chance yet to verify what do these calls do in the engine source.

function loadSceneGraph( %scenegraph_name )
{
   
   %scenegraph = sceneWindow2D.getSceneGraph();
   if (isObject(%scenegraph))
   {
      if( isObject( %scenegraph.getGlobalTileMap() ) )
         %scenegraph.getGlobalTileMap().delete();
         
      %scenegraph.delete();
   }

   if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Landscape )
   {
      if( $platform $= "ipad" || $platform_simul $= "ipad") 
      {

         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "1024 768";    
         };
      }
      else
      {
         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "960 640";    
         };          
      } 
   }
   else if ( $pref::iDevice::ScreenOrientation  == $iDevice::constant::Portrait )
   {
      if( $platform $= "ipad" || $platform_simul $= "ipad") 
      {

         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "768 1024";    
         };
      }
      else
      {
         %scenegraph = new t2dSceneGraph( %scenegraph_name ) 
         {
            cameraPosition = "0 0";    
            cameraSize = "640 960";    
         };          
      } 
      
      
   }


   sceneWindow2D.setSceneGraph(%scenegraph);
   %scenegraph.performPostInit();
   %cameraPosition = sceneWindow2D.getCurrentCameraPosition();
   %cameraSize = t2dVectorSub(getWords(sceneWindow2D.getCurrentCameraArea(), 2, 3),
                              getWords(sceneWindow2D.getCurrentCameraArea(), 0, 1));
                              
   if (%scenegraph.cameraPosition !$= "")
      %cameraPosition = %scenegraph.cameraPosition;
   if (%scenegraph.cameraSize !$= "")
      %cameraSize = %scenegraph.cameraSize;
      
   sceneWindow2D.setCurrentCameraPosition(%cameraPosition, %cameraSize);

}