Game Development Community

Td2StaticSprite save issue

by Guy Lewis · in Torque Game Builder · 03/18/2007 (3:05 pm) · 4 replies

I have ran into an issue when attempting to save a t2dStaticSpriteObject with a datablock and a frame set.
When attempting to load the object I get this error:
't2dStaticSprite::setFrame() - Cannot set Frame without existing t2dImageMapDatablock Datablock!'

Testing verified that it is because TGB tries to set the frame before loading the datablock.
When the image is saved it writes the frame info before the config datablock.

Here is what the object saves
//--- OBJECT WRITE BEGIN ---
new t2dStaticSprite(Wink_1) {
   frame = "0";
   config = "winkDatablock";
   position = "12.588 -9.659";
   LinkPoints = "0.000 0.000";
   MountTrackRotation = "0";
   MountOwned = "0";
   MountInheritAttributes = "0";
      type = "1";
};
//--- OBJECT WRITE END ---

moving the frame statement below the config line allows the object to load fine.

I am able to work around it in my code. Just wanted to make folks aware of this.

#1
03/18/2007 (3:10 pm)
@Guy, interesting find ... I wouldn't have thought the order you put the fields would matter in a create block ... apparently they do ... always good to know --
#2
03/18/2007 (9:07 pm)
Ya, that was always my impression too. I started playing with saving to design a level editor for the project I am currently playing with and ran across this.

The really strange thing is I looked at the save routine in the source and it should definately write the config before the frame. I haven't tried to trace it all the way back through, but from my initial look it should work.

God bless OOP. . . as long as you don't have to debug it
#3
03/25/2007 (5:11 pm)
OK,
This was driving me crazy and I had to know why. Digging through the save routine, here is what is happening. It all has to do with the interitance and object save order.

t2dStaticSprite is inherited from t2dSceneObject. When an object is saved, it saves the members down the inheritance tree like so, t2dStaticSprite->t2dSceneObject->simObject.

The imageMap and frame are defined in t2dStaticSprite and config is defined in t2dSceneObject. This causes save to write imagemap and frame before config. This will only occur on t2dSprites and only if the image map is defined in the config file and frame is not or the value of frame has changed from the datablock value.

When the object is loaded from a file, as soon as frame is loaded it tries to get the image frame and fails because the image hasn't been loaded yet.

I worked around it by defining the imageMap at object creation time and not in the datablock.

Hopefully this will save someone the pain I went through figuring this out.
#4
03/25/2007 (5:16 pm)
OK,
This was driving me crazy and I had to know why. Digging through the save routine, here is what is happening. It all has to do with the inheritance and object save order.

t2dStaticSprite is inherited from t2dSceneObject. When an object is saved, it saves the members down the inheritance tree like so, t2dStaticSprite->t2dSceneObject->simObject.

The imageMap and frame are defined in t2dStaticSprite and config is defined in t2dSceneObject. This causes save to write imagemap and frame before config. This will only occur on t2dSprites and only if the image map is defined in the config file and frame is not or the value of frame has changed from the datablock value.

When the object is loaded from a file, as soon as frame is loaded it tries to get the image frame and fails because the image hasn't been loaded yet.

I worked around it by defining the imageMap at object creation time and not in the datablock.

Hopefully this will save someone the pain I went through figuring this out.