Create a new object.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Create a new object.

Rob Van Pamel
Hello everybody

I sometimes get an error when i try to add an object to the Tspace.
I do this as following.
-----------
  CODE
-----------
temp := Redcube new.
cube translationX:(cube x)asInteger y:(cube y)asInteger z:(cube z)asInteger.
space addChild:cube.

Now this works fine. But i am  working with a database which reads out data and that data represents the objects that i add to the TSpace. I do this every 5 seconds with a stepper, and when i found out that an object is in the database but isn't yet in the Tspace i add it in the same way i add it before.
It works but sometimes i get an error like this

Error : This object has no name.
But when i try to debug it, i don't see my code anywhere. Not even in the Full Stack. It's about TFarref ,TMutexSet and so on ...

Anybody who has had something like this ?

Thanx in advantage
  Rob

Reply | Threaded
Open this post in threaded view
|

Re: Create a new object.

Joshua Gargus-2
It seems likely that you're not adding object properly.  How are you  
getting a reference to the space that you want to add to?  Where is  
the stepper running? (on a Croquet object? on a Morphic object? in a  
Process using Delay>>wait?)

I suspect that you're running the stepper from an object "inside the  
island", which is normally fine, but not if you're triggering a non-
replicated side-effect like reading an object from a database and  
adding it to the space.  Think of it this way:

Succinctly put, the basis of Croquet's replication model is "If you  
have two identical replicas of a world, and they subsequently process  
the identical events in the same order, then the replicas will remain  
identical".  (putting it even more succinctly: "determinism").

 From your rather sketchy description, I can imagine that things  
might go something like this:
        - you start off with 2 synced replicas
        - every 5 seconds, a stepper (in both replicas) checks if there is  
something new in the database

If this is correct, then you are already in trouble, because you have  
introduced non-determinism.  There is no guarantee that both replicas  
will get the same result from the database lookup.  This is  
especially true if only one of the machines attempts the database  
connection and creates the object in the space (how can the other  
replica possibly know that an object has been created?), but is also  
true if both machines are connecting to the same (perhaps  
distributed) database.

Here's one way that the above scenario might produce symptoms like  
the stack trace you observed...

If you mouse over the newly created object, all replicas of the  
object should be notified so that they can respond appropriately.  
This notification occurs by sending a replicated message via the  
TFarRef to the object.  The mouse-over processing occurs during  
picking, which happens during rendering (i.e. between ticks of the  
island clock).  The pick operation attempts to find the TFarRef  
corresponding to the picked object, but fails because of the way that  
the object was created (i.e. via a non-replicated action on one  
island replica).

Does this guess sound close?  Could you describe the structure of  
your code in a bit more detail?

Cheers,
Josh


On Nov 27, 2006, at 1:47 AM, Rob Van Pamel wrote:

> Hello everybody
>
> I sometimes get an error when i try to add an object to the Tspace.
> I do this as following.
> -----------
>   CODE
> -----------
> temp := Redcube new.
> cube translationX:(cube x)asInteger y:(cube y)asInteger z:(cube z)
> asInteger.
> space addChild:cube.
>
> Now this works fine. But i am  working with a database which reads  
> out data and that data represents the objects that i add to the  
> TSpace. I do this every 5 seconds with a stepper, and when i found  
> out that an object is in the database but isn't yet in the Tspace i  
> add it in the same way i add it before.
> It works but sometimes i get an error like this
>
> Error : This object has no name.
> But when i try to debug it, i don't see my code anywhere. Not even  
> in the Full Stack. It's about TFarref ,TMutexSet and so on ...
>
> Anybody who has had something like this ?
>
> Thanx in advantage
>   Rob
>


Reply | Threaded
Open this post in threaded view
|

Re: Create a new object.

Joshua Gargus-2
In reply to this post by Rob Van Pamel
Rob, I forwarded one of your previous emails to the list to provide  
context for others who might wish to learn from this discussion.  I  
hope that you don't mind.

On Nov 27, 2006, at 6:03 AM, Rob Van Pamel wrote:

> Hi josh,
>
> I'm sorry but I don't understand it completely.
> I understand that I have to work with a TfarReference because my  
> Island is
> isolated from my stepper.

That's correct.

> To access my island I created an instance variable not an a global  
> one. But
> it is available al over the class that's why I called it an global  
> variable.

OK.  The reason I called it a global variable is that you registered  
it as an Island global variable with #registerGlobal:

>
> So now I have to create an global variable with registerglobal in the
> NavigatorMaster and then I can access this variable trough future  
> sends?
>

No, you should be able to create the global variable just fine in  
NavigationWorld, just like you are.  What you should not do is stash  
a direct reference to the space and then reference it from your  
stepper. After the island is finished creating, you can access the  
'island global' as I described, which gives you a TFarRef to the space.

spaceRef := island "a TFarRef to the island" future at: #mainEntry.

islandRef := spaceRef island

> Do you perhaps have a example in which you work with these future  
> sends?
> Because I'm trying to find out but I don't think I'm going to make it.

There are (at least) two approaches you might take.  The following  
code assumes that you have already executed the line (in  
NavigationMaster)
        island := harness createIsland: NavigatorWorld named: myName.
and that you have obtained a reference to the space:
        spaceRef := island "a TFarRef to the island" future at: #mainEntry.
        spaceRef wait.  "wait for the future message to resolve"

(I won't get into details, but it would have been fine to send other  
future messages to spaceRef without first calling #wait)

Now assume that you have looked in your database and decided that you  
need to create a new Foocube in the space.  The first approach is to  
gradually construct the object via a series of future messages:

        fooCubeRef := island future new: Foocube.
        fooCubeRef future setParameterOne: dataFromDatabase.
        fooCubeRef future setParameterTwo: moreDataFromDatabase.
        "etc."
        spaceRef future addChild: fooCubeRef

A second approach is to completely create the Foocube outside the  
island, then serialize it, then instantiate a copy in the space by  
deserializing it.  (a varation on this approach might be very good  
for you:  you could skip the Foocube creation step and directly store  
the serialized data in the database.

        fooCube := Foocube new.
        fooCube setParameterOne: dataFromDatabase.
        fooCube setParameterTwo: moreDataFromDatabase.
        serialized := TIslandCopier new export: fooCube.
        fooCubeRef := TIslandCopier new import: serialized to island.
        spaceRef future addChild: fooCubeRef

Let me know how it goes.  If you have problems, it might be because I  
made a mistake somewhere (I didn't run the code).

Josh



>
> Thanks in advantage
>   Rob Van Pamel
>
>