I've modified Celestia to a network time synchonizing program
the function to set time is appCore->getSimulation()->setTime(curTime);
the time data(curTime) is sent from the network server,so it can share the same time with the server.
but sometimes the Celestia program crash,when it synchonize time with the network server,
though not very often, it troubles me.
I've look at the debugging information and it shows that when the time is set, the velocity and position is also calculated,so there's a mistake.
How to solve this problem?
Thanks.
How to set Celestia's time in C++
Forum rules
Please help to make this forum more useful by checking the FAQs before posting! Keep it clean, keep it civil, keep it truthful, stay on topic, be responsible, share your knowledge.
Please help to make this forum more useful by checking the FAQs before posting! Keep it clean, keep it civil, keep it truthful, stay on topic, be responsible, share your knowledge.
Re: How to set Celestia's time in C++
SU27,
Your comments are ambiguous.
Do you mean that your C++ code is calculating a velocity? (it should not)
What 'velocity' do you mean? Please be specific about the variables involved.
My understanding is that Celestia should not be calculating any velocity values based on the current and previous time, although it can use externally supplied velocities to calculate the position of an object at a particular time.
Celestia is supposed to be able to calculate the positions of all objects on the screen at any simulated time, whether that time is before or after the time of the previous set of screen calculations. The code in Celestia, and the code in any Lua modules that you provide, must not assume that simulated time is monotonically increasing. Some Addons do assume that the simulated time is always increasing and will do strange things if it goes backward, but Celestia should not crash.
Your comments are ambiguous.
Do you mean that your C++ code is calculating a velocity? (it should not)
What 'velocity' do you mean? Please be specific about the variables involved.
My understanding is that Celestia should not be calculating any velocity values based on the current and previous time, although it can use externally supplied velocities to calculate the position of an object at a particular time.
Celestia is supposed to be able to calculate the positions of all objects on the screen at any simulated time, whether that time is before or after the time of the previous set of screen calculations. The code in Celestia, and the code in any Lua modules that you provide, must not assume that simulated time is monotonically increasing. Some Addons do assume that the simulated time is always increasing and will do strange things if it goes backward, but Celestia should not crash.
Selden
Re: How to set Celestia's time in C++
selden wrote:SU27,
Your comments are ambiguous.
Do you mean that your C++ code is calculating a velocity? (it should not)
sorry, selden,my English is not so good.
I mean that I'm writing a time synchonizing function for Celestia,
which is listening to the time data sent from a server via UDP protocol.
what I want is to set the time according to the server's data,
so I wrote "appCore->getSimulation()->setTime" in this function,
but however, I find sometimes it crashes....
bool CTimeSync::datagramHandler( )
{
SSyncPkg pkgBuf;
int rl = m_pSock->getDatagram((char*)(&pkgBuf), sizeof( SSyncPkg)); //from UDP Socket
//Test the length of UDP data
if ( rl != sizeof( SSyncPkg) )
{
return false;
}
//Parse the UDP data
if( strcmp( pkgBuf.header, SYNC_PKG_HEADER))
{
return false;
}
//Parse the UDP data
if ( !strcmp(pkgBuf.cmd, SYNC_CMD_TIME) ) // Synchonize time
{
appCore->getSimulation()->setTime(pkgBuf.tdb);
}
return true;
}
Above is my code, I find simply call celestiacore and settime, sometimes leads to crash....
Maybe because Celestia is a multi-thread program,
Should I pause the celestiacore's simulation when I settime or?
Re: How to set Celestia's time in C++
Celestia's internal time should only be changed before Celestia starts the calculations necessary for a screen update. If the time is changed asynchronously in the middle of a screen update, I'm sure strange things will happen, including crashes.
I am not familiar with the details of Celestia's code or when your UDP function is called. If your routine is called asynchronously by the network code, you would need to store the new time in an intermediate global variable and use that variable to update Celestia's internal time when the current screen update has completed.
I am not familiar with the details of Celestia's code or when your UDP function is called. If your routine is called asynchronously by the network code, you would need to store the new time in an intermediate global variable and use that variable to update Celestia's internal time when the current screen update has completed.
Selden
-
- Site Admin
- Posts: 4211
- Joined: 28.01.2002
- With us: 22 years 9 months
- Location: Seattle, Washington, USA
Re: How to set Celestia's time in C++
Su27,
I know that other people have synchronized Celestia's time using data read from a network connection, so it's possible. Setting the time shouldn't cause a crash, even if it's done in a separate thread (though as Selden mentioned, you may see strange results if you update the time mid-frame.) Have you tried building a debug version of Celestia and running that? It would be very helpful if you could provide the call stack at the time of the crash.
--Chris
I know that other people have synchronized Celestia's time using data read from a network connection, so it's possible. Setting the time shouldn't cause a crash, even if it's done in a separate thread (though as Selden mentioned, you may see strange results if you update the time mid-frame.) Have you tried building a debug version of Celestia and running that? It would be very helpful if you could provide the call stack at the time of the crash.
--Chris
Re: How to set Celestia's time in C++
chris wrote:Su27,
I know that other people have synchronized Celestia's time using data read from a network connection, so it's possible. Setting the time shouldn't cause a crash, even if it's done in a separate thread (though as Selden mentioned, you may see strange results if you update the time mid-frame.) Have you tried building a debug version of Celestia and running that? It would be very helpful if you could provide the call stack at the time of the crash.
--Chris
Thank you very much Selden and Chris
I've tried the method, add the time changing part into tick() function of celestiacore.cpp and it works good ,
Best wishes!