universe problems

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
jbarcz1
Creative Contributor
Posts: 226
Joined: Thu Jun 26, 2003 4:33 pm
Location: Baltimore, MD

universe problems

#1 Post by jbarcz1 »

I am running the app by choosing single player from the intro screen (no servers running). The server sends me back a perfectly good universe state in the game start message, but when the universe tries to reconstruct it using the SetUniverse() method, it doesn't reconstruct anything, because the object factory is returning a NULL pointer. I was never seeing star systems on the map before and this explains why. Now its causing the fleet window to crash because I'm trying to look up fleets that are not there. Is/was anybody else having this happen? Was there a fix to it that somehow didn't get committed?

Zach, did you make any changes to clientUniverse after 8/27 when (according to the CVS log) you removed #defines?

EDIT: It'd probably be helpful to know I'm running it under WinXP. My source is current as of yesterday, before Zach's commit this evening.
Empire Team Lead

jbarcz1
Creative Contributor
Posts: 226
Joined: Thu Jun 26, 2003 4:33 pm
Location: Baltimore, MD

#2 Post by jbarcz1 »

Ok, figured out what it was. The object list in the universe element that I get from the server has the objects encoded like this:

<m_objects>
<univ_object>
<System>
<visibility value="1"/>
<UniverseObject>
<visibility value="1"/>
<m_id value="0"/>
<m_name>"<![CDATA[System0]]>"</m_name>
<m_x value="193"/>
<m_y value="808"/>
</UniverseObject>
<m_star value="0"/>
</System>
</univ_object>
.... etc etc

Now, the code in ClientUniverse trying to construct these guys is:
UniverseObject* obj = m_factory.GenerateObject(elem.Child("m_objects").Child(i);

And it's bombing because Child(i)'s tag is univ_object, so the factory doesn't know what to do with it.

Changing it to Child(i).Child(0) causes a different problem, it says:
Attempted to construct a ProdCenter from an XMLElement that had a tag other than "ProdCenter"

Unless somebody else would prefer to do it, I'm going to go through the Serialization code for the entire universe object hierarchy and make sure it all works.
Empire Team Lead

tzlaine
Programming Lead Emeritus
Posts: 1092
Joined: Thu Jun 26, 2003 1:33 pm

#3 Post by tzlaine »

I think this is a code version issue; the current version of System::XMLEncode() doesn't generate XML that looks anything like what you've posted above. Here's part of a recent universe dump:

Code: Select all

  <ClientUniverse>
    <m_objects>
      <System>
        <visibility value="0"/>
        <UniverseObject>
          <visibility value="0"/>
          <m_id value="0"/>
          <m_name>"<![CDATA[System0]]>"</m_name>
          <m_x value="783"/>
          <m_y value="798"/>
          <m_owners>
            <owner value="0"/>
          </m_owners>
          <m_system_id value="-1"/>
        </UniverseObject>
        <m_star value="2"/>
        <m_orbits value="2"/>
        <m_objects>
          <map_object id="153" orbit="0"/>
          <map_object id="154" orbit="1"/>
        </m_objects>
        <m_starlanes_wormholes/>
      </System>
Don't forget that for some code changes to work, you need to rebuild both the server and the client, since they both need to generate and parse XML objects the same way.

jbarcz1
Creative Contributor
Posts: 226
Joined: Thu Jun 26, 2003 4:33 pm
Location: Baltimore, MD

another...

#4 Post by jbarcz1 »

The code I have now compiles in Cygwin, but I have trouble linking, mostly due to the fact that my cygwin libraries are either out of date or non-existant, or otherwise problematic. I've switched back to Dev-Cpp for the moment, and have managed to uncover a bug.

Somehow, I'm getting the server to send me the following planet in the game_start message:
<Planet>
<UniverseObject>
<visibility value="0"/>
<m_id value="251"/>
<m_name>"<![CDATA[Henge II]]>"</m_name>
<m_x value="-100000"/>
<m_y value="-100000"/>
<m_owners/>
<m_system_id value="41"/>
</UniverseObject>
<PopCenter>
<m_pop value="0"/>
<m_max_pop value="70"/>
<m_growth value="0"/>
<m_race value="-1"/>
</PopCenter>
<ProdCenter>
<visibility value="0"/>
<m_primary value="0"/>
<m_secondary value="0"/>
<m_workforce value="0"/>
<m_industry_factor value="0"/>
<m_currently_building value="0"/>
<m_rollover value="8.693817338661233e-311"/>
</ProdCenter>
<m_type value="5"/>
<m_size value="3"/>
<m_def_bases value="0"/>
</Planet>

Note that m_rollover value is a very very small number. It looks like there's a NAN or something getting stuck in there. boost::lexical_cast is choking as soon as it sees this and throws a bad_lexical_cast. This in turn causes the client to sputter and die. I've got a nice, verbose log of it available to anybody who's interested.

I'm going to comment out the lexical cast that catches it, and see if I can get the galaxy map to display right otherwise.
Empire Team Lead

jbarcz1
Creative Contributor
Posts: 226
Joined: Thu Jun 26, 2003 4:33 pm
Location: Baltimore, MD

#5 Post by jbarcz1 »

Galaxy map pops up normally once I "fixed" the problem.
My complements to Zach and the art team, it's looking absolutely beautiful.

As to the bug, Has anybody else seen strange numbers get produced like I did? Or am I the only one?
Empire Team Lead

tzlaine
Programming Lead Emeritus
Posts: 1092
Joined: Thu Jun 26, 2003 1:33 pm

#6 Post by tzlaine »

I haven't seen this problem, and I'm really baffled by it. First off, the position of the planet is the invalid position constant (-10000) in both x and y. That's obviously wrong. Also, I'm shocked that lexical_cast barfs when it sees a very small number like that, and I'm not sure why the small number is there instead of 0. I'm currently reworking the universe generation stuff, so maybe this stuff will all work itself out. I'd like you to post the relevant portion of your logs so I can have a look though, just in case.

EDIT: Well, I found at least part of the problem in about 90 seconds. m_rollover is uninitialized in the ProdCenter ctor. This is why one should always initialize every data member that does not have a default ctor, in the ctor of the containing class.

jbarcz1
Creative Contributor
Posts: 226
Joined: Thu Jun 26, 2003 4:33 pm
Location: Baltimore, MD

#7 Post by jbarcz1 »

Well, you've already seen the relevant portion of my universe dump. I've got a log from the client says the following:

Tue Sep 16 03:11:17 2003 DEBUG : Creating child 246 with tag: Planet
Tue Sep 16 03:11:17 2003 DEBUG : Creating child 247 with tag: Planet
Tue Sep 16 03:11:17 2003 DEBUG : Creating child 248 with tag: Planet
Tue Sep 16 03:11:17 2003 DEBUG : Creating child 249 with tag: Planet
Tue Sep 16 03:11:17 2003 DEBUG : Creating child 250 with tag: Planet
Tue Sep 16 03:11:17 2003 DEBUG : Creating child 251 with tag: Planet
Tue Sep 16 03:11:18 2003 DEBUG : caught exception: boost bad lexical cast: bad lexical cast: source type value could not be interpreted as target

This is the lexical cast for m_rollover that throws the exception.


There are lots of planets in my universe dump with the invalid position constant. Starting at around Object ID = 150.

For example:
<Planet>
<UniverseObject>
<visibility value="0"/>
<m_id value="150"/>
<m_name>"<![CDATA[Tiwaz I]]>"</m_name>
<m_x value="-100000"/>
<m_y value="-100000"/>
<m_owners>
<owner value="0"/>
</m_owners>
<m_system_id value="72"/>
</UniverseObject>
<PopCenter>
<m_pop value="20"/>
<m_max_pop value="70"/>
<m_growth value="0"/>
<m_race value="-1"/>
</PopCenter>
<ProdCenter>
<visibility value="0"/>
<m_primary value="0"/>
<m_secondary value="0"/>
<m_workforce value="20"/>
<m_industry_factor value="0.1"/>
<m_currently_building value="0"/>
<m_rollover value="0"/>
</ProdCenter>
<m_type value="4"/>
<m_size value="3"/>
<m_def_bases value="3"/>
</Planet>

In fact, it appears that each and every planet has got an invalid position. This is probably because planets are contained in systems and someone saw fit not to set their position to a redundant value.
Empire Team Lead

tzlaine
Programming Lead Emeritus
Posts: 1092
Joined: Thu Jun 26, 2003 1:33 pm

#8 Post by tzlaine »

That's true, but an object probably should takes its system's location when it is added to a system (that's not currently happening). Are you using the latest code? The log entries resemble some of the older code.

jbarcz1
Creative Contributor
Posts: 226
Joined: Thu Jun 26, 2003 4:33 pm
Location: Baltimore, MD

#9 Post by jbarcz1 »

I added some writes to the log in SetUniverse to get it to trace through universe creation for me and figure out where it was bombing.

My versions of the human client code and the universe code are up to date. I didn't go through and status the other stuff but I figure it is too, I did an update last night and should have gottten any changes.
Empire Team Lead

Post Reply