Are there any plans to make pyglet objects amenable to
pickling?
2011/7/14 greenmoss <ktyg...@yoderhome.com>:
> --
> You received this message because you are subscribed to the Google Groups "pyglet-users" group.
> To post to this group, send email to pyglet...@googlegroups.com.
> To unsubscribe from this group, send email to pyglet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To post to this group, send email to pyglet...@googlegroups.com.
To unsubscribe from this group, send email to pyglet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.
Let me preface my response by saying that I'm inexperienced, so I
could well be taking a suboptimal approach. That being the case, the
most logical way to handle game and graphics data for an in-game
object would IMHO be to attach it to a single python object. This in
turn leads to manual getstate/setstate overrides, extra code, etc.
Is there some other way that people handle this type of situation?
Also, do not use pickle, its insecure.
The way I tend to handle this kind of thing is that
the game object doesn't contain a direct reference to
the graphics data. Instead it contains some piece of
identifying data, such as an integer or string, and
a global dict is used to map this to the associated
graphics data.
If you like, you can hide this lookup behind a property,
so that the object appears to have the graphics data
as an attribute.
--
Greg
> The only reason that the python documentation issues the following
> warning: "/The pickle module is not intended to be secure against
> erroneous or maliciously constructed data. Never unpickle data received
> from an untrusted or unauthenticated source/", is that it is possible to
> hand-craft a file that will crash the unpickle process.
No, it's somewhat worse than that: it's possible to construct
a pickle that will call an arbitrary class or function in your
application with arbitrary arguments. It's conceivable that a
malicious opponent could use this to pwn your machine.
So you need to treat untrusted pickles with the same level of
caution as untrusted executables.
--
Greg
2011/7/14 Tristam MacDonald <swift...@gmail.com>:
After reading the responses in this thread relating how to handle
saving pyglet game state using pickle, the general idea seems to be
"don't do it that way", with various implementations of how to save
state while avoiding pickling pyglet objects. The solution I have been
using, eg getstate/setstate has so far worked for me, so this is
probably what I will continue to use.
However, while hopefully not sounding too presumptuous, it strikes me
that in theory and in practice a framework such as pyglet tries to
make it easier for game developers by providing convenience methods
for common back-end chores. Gracefully handling pickle and unpickle
requests seems to me compatible with this goal[1]. Am I
misunderstanding the aims of the pyglet project?
[1] Note that I'm making no claims or demands about implementation.
Instead I am opining that it is *desirable*. Rebuttals are of course
welcome.
No, it's somewhat worse than that: it's possible to constructa pickle that will call an arbitrary class or function in your
application with arbitrary arguments. It's conceivable that a
malicious opponent could use this to pwn your machine.
So you need to treat untrusted pickles with the same level of
caution as untrusted executables.
Since the best way to deal with pickling of pyglet objects
in saved games is usually to avoid attempting to pickle them
in the first place, it's hard to see how pyglet could do
anything to make this more convenient.
I stand by my belief that you should redesign your game
architecture so that there are no direct references from
your game logic objects to your graphics objects.
Take a piece of paper and draw a line down the middle.
Write the heading "User Interface and Graphics Objects"
on the left, and "Game State Objects" on the right.
Draw boxes representing the various objects on their
respective sides, with arrows between them representing
references.
Now, make sure that arrows that cross the dividing line
point *only* from the left side to the right side. If you
ever find yourself wanting to create an arrow from the
right side to the left side, take a deep breath, count to
ten and think of some other way to make the association.
--
Greg
--
You received this message because you are subscribed to the Google Groups "pyglet-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pyglet-users/-/mVkz7ifzGzkJ.
I may be wrong but I think these ideas of pickling Sprites are totally swimming against the current. It is much easier and more useful to only pickle simple value-type objects (e.g. integers and strings), and re-construct any required Sprites by calling the Sprite constructor as usual when you restart the application.
You're missing the point: attempting to save OpenGL state
in a game save file is a wrongheaded thing to be doing in
the first place, IMO.
--
Greg
Uh. I'm not talking about serialisation. I used the word 'pickle'
since that's what it all started with, but at one point, the talk
diverged to a way to save the current windows and objects and restore
them. Serialising or not. You aren't 'serialising' unless you choose
to in this. This is probably my fault for still saying pickle, etc.
Just to be clear, this is NOT a way of saving/loading your game, nor
is it a good way to theoretically. This is where the discussion
started, but I kind of went off on a tangent.
This is meant to be a
way to be able to close and restore the actual graphics themselves
(generally on the same machine, but similar ones will do fine).
Literally, you'd be able to close, then when you start it again,
EVERYTHING would be as you left it (provided you make sure you save
every thing you need and load them back properly). It's a way of
'pickling' the actual graphics objects. If you serialise the objects
and store them, you could say you're actually pickling them.