About Store Forum Documentation Contact



Post Reply 
program crash on loading a savegame
Author Message
yvanvds Offline
Member

Post: #1
program crash on loading a savegame
Hey.

My program crashes every time when i load a saved game. First it stalls for about 5 seconds, and after that i get an "Access violation reading location x".

If I load my world in the saving & loading tutorial the game does not crash, but loading a game takes about 8 seconds. Of course nothing much is going on when using the tutorial, compared with the real program.

The world has a few 100 objects, but even then 8 seconds seems like a very long time to load. I assume that loading happens in a separate thread, because i see a thread finish right after i load the savegame?

Are there any known do's or don't when loading a game?

One thing i'd like to inspect are all the objects in the world. In the world editor i can click on all of them, but i could very easily miss one. Is there a way to iterate through them, so that i can see which one are included in a savegame?

Also a way to read the savegame with an editor would be handy. I'd like to inspect that too, but i can only make out a few words. Is there a way to save it as text?

Regards,

yvan
11-20-2010 10:02 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: program crash on loading a savegame
Are you using custom object classes?
And are you overriding in them save/load methods?

Please paste those codes.
11-20-2010 10:13 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #3
RE: program crash on loading a savegame
Well, I extended the Chr struct for my player, and the Item class for my objects. But I did not add a custom save method yet. Should I have?

This is all code i've added about saving and loading, located inside the update function:

Code:
    if(Kb.bp(KB_F3)) {
        Game::World.load("savegame");
    }
    if(Kb.bp(KB_F2)) {
        Game::World.save("savegame");
    }

I've also tried loading the path.world from the tutorials into my game. It also crashes. So i guess it's about the code, not the world. Still, everything works as long as i don't try to load a savegame.

While debugging i noticed the game halts during the day/night update, almost like in the tutorials.
Code:
(sky = Lerp(tl[prev].sky, tl[next].sky, step);

And indeed, those variables are not defined anymore. But if I disable that part of the program, the problem just happens someplace else. When I disable all input checking functions, the day/night functions and the soundsystem, it's ok. If I re-enable just one of them it works also. Doesn't matter which one.

Clearly some parts of the memory get overwritten. But if I was reckless with memory management in other parts of the game, why would it happen only when loading?
11-20-2010 10:55 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: program crash on loading a savegame
I think you have an error somewhere else in the codes, I've just tested ERPG2 save/load few times on the main map, and it works fine.

Quote:But if I was reckless with memory management in other parts of the game, why would it happen only when loading?
bugs are just like that smile they not always show up, sometime only under some circumstances

the best thing you can do is Binary Bug Huntâ„¢, comment half of the codes, check if works, if it does, then uncomment it, and comment the other half of the codes, and so on.. (narrow down the problem)

Sometimes helps to run "with debugging" and "without debugging" - error can occur at different places, if it crashes you can also select debug (when no debugging was enabled) under vista/win7.
11-20-2010 11:20 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #5
RE: program crash on loading a savegame
Doing just that. And I notice that most off it relates indirectly to calls to the player object. And that several variables i added to the player struct are not correct anymore after loading a savegame.

If I add pointers or variables to my player class, should i also initialize them again after loading a saved game? I thought i should not, if i don't want to keep their value after I load a game. But the bool itemSelected, for instance, is changed to true after i load a saved game.

I think it's rather trivial, but here's my current player.h:

PHP Code:
#pragma once
#include "cInventory.h"

// extend character structure by defining a player class based on the character

struct Player Game::Chr {
    
Vec ctrl_pos;

     
// get / set
   
virtual Vec    pos   (                ) {return __super::pos   ();}
   
virtual Matrix matrix(                ) {return __super::matrix();}
   
virtual void   pos   (C Vec    &pos   );
   
virtual void   matrix(C Matrix &matrix);

    
// need to remember last mouse position when the mouse is hidden
    
Vec2 mouse_pos;

    
// to select items on screen
    
Item *selectedItem;
    
Item *grabbedItem;
    
bool itemSelected;
    
    
// inventory system
    
cInventory inv;
    
Memx<Game::Obj> *itemContainer();
    
void itemRemoved(Game::Obj &item);
    
void itemRemoved();
    
void itemAdded(Game::Obj &item);
    
    
// grabber for objects
    
Grab grab;

    
// manage
  
virtual void create(Game::ObjParams &obj);
    
    
Player();
    
virtual Bool update(); // here we'll update the player
    
virtual UInt drawPrepare(); // extend drawing to disable head rendering in FPP mode
    
virtual void animate();


};

extern Game::ObjMemx<PlayerPlayers;
extern Player player

And the player.cpp:

PHP Code:
#include "stdafx.h"
#include "game.h"
#include "cCamera.h"
#include "cPlayer.h"

// container for all players
Game::ObjMemx<PlayerPlayers;
// the current player pointer
Player player;

Player::Player() {
    
__super::Chr();
    
itemSelected false;
    
ctrl_pos.zero();
}

Memx<Game::Obj> * Player::itemContainer() {
    
Memx<Game::Obj> &items inv.items;
    return &
items;
}

void Player::itemRemoved(Game::Obj &item) {
    
inv.itemRemoved(item);
}

void Player::itemRemoved() {
    
inv.itemRemoved();
}

void Player::itemAdded(Game::Obj &item) {
    
inv.itemAdded(item);
}

Bool Player::update() {
    
ctrl_pos=ctrl.actor.pos();
    
inv.update(T);

    return 
__super::update();
}

UInt Player::drawPrepare() {
    
mesh Meshes("obj/chr/aiko/lambert.mesh");
    
// disable drawing head when we're in FPP mode
    
Bool hide_head = (camera.view == VIEW_FPP && mesh); 
    if (
hide_headmesh->hide("head"); 
    
UInt modes __super::drawPrepare(); 

    
// un-hide "head" mesh part, so other objects which use the same 
    // mesh will have the head rendered properly
    
if (hide_headmesh->show("head"); 
    return 
modes;
}

void Player::animate() {
    
__super::animate();
}
    
/******************************************************************************/
// GET / SET
/******************************************************************************/
void Player::pos(C Vec &pos) {
   
Vec delta=pos-T.pos();
   
__super::pos(pos);

   
ctrl_pos+=delta;
}
/******************************************************************************/
void Player::matrix(C Matrix &matrix) {
   
Vec delta=matrix.pos-T.matrix().pos;
   
__super::matrix(matrix);

   
ctrl_pos+=delta;
}

void Player::create(Game::ObjParams &obj) {
   
__super::create(obj);
   
ctrl_pos pos();

11-21-2010 12:51 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: program crash on loading a savegame
Hi,

You're missing some basics:

you need to clear these pointers in player constructor
Item *selectedItem;
Item *grabbedItem;

also
Item* is not a good choice, you should use Reference<Item> please check tutorial (object references) and tutorial inventory.

also you shouldn't store global
Player *player;
what you want is always check:
if(Players.elms())Players[0].
11-21-2010 03:00 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #7
RE: program crash on loading a savegame
Ah! That global pointer to player seemed such a good idea at the time :-) Turns out that was the one causing all the problems. Loading the game works as it should now.

Thanks for the help.
11-21-2010 08:57 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #8
RE: program crash on loading a savegame
Mmm. Something else is wrong now. Saving and loading works as it should, with the following code (like in the tutorial):

Code:
    if(Kb.bp(KB_F3)) {
        Game::World.load("savegame");
    }
    if(Kb.bp(KB_F2)) {
        Game::World.save("savegame");
    }

But only if i stay more or less close to the place my character starts in the world. If I save the world, go to the other side and load the last save, I stay at my current position with no avatar and a static camera.

Overriding the IO functions in my player class triggers this behaviour instantly, even if i save and load in the starting area. Adding a breakpoint in this code learns me they're not even called. Code:

Code:
void Player::save(File &f) {
    __super::save(f);
  f << ctrl_pos;
}

Bool Player::load(File &f) {
  if(__super::load(f)) {
        f >> ctrl_pos;
  }
  return false;
}

So what is missing here? I shouldn't override the Game::World.save function, should I? The player object is created in the world editor, and loaded at Game Init, with

Code:
Game::World.init()
   .setObjType(Statics,OBJ_STATIC)
   .setObjType(Part,OBJ_PARTICLES)
   .setObjType(Players,OBJ_PLAYER)
   .setObjType(Items, OBJ_ITEM)
   .setObjType(Kinematics, OBJ_KINEMATIC)
   .setObjType(ObjLightPoints,OBJ_LIGHT_POINT)
   .setObjType(ObjLightCones,OBJ_LIGHT_CONE)
   .New("world/attrx.world");

Or should I create the player object in the code, instead of with the world editor?
11-23-2010 01:40 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: program crash on loading a savegame
it's ok, you just need to save/load camera in game world save/load functions
11-23-2010 02:16 PM
Find all posts by this user Quote this message in a reply
Post Reply