Hello,
I am using the time_facet class to be able to output time and date (in
millisecond precision) in some weird format someone cooked up.
I have to generate a timestamp everytime I send something to another
application.
The following testprogram reproduces my error (using Visual Studio 2005):
#include <iostream>
#include
using namespace boost::posix_time;
using namespace std;
void imbue_crash_test(time_facet* formatter, ptime outputTime ){
stringstream tempStream;
tempStream.imbue(locale(cout.getloc(), formatter));
tempStream<format("%Y %m %d %H %M %S %f");
imbue_crash_test(timeFormatter, microsec_clock::universal_time());
imbue_crash_test(timeFormatter, microsec_clock::universal_time());
system("pause");
return 0;
}
which gives me an access violation while writing the "outputTime" to the
stringstream the second time.
When i stop the app and check the "formatter" instance i notice that the
value of "m_time_duration_format" gives "<BadPtr>" probably indicating
that the formatter has been deleted.
Does anyone have a clue as to why this would be?
The problem is resolved by making sure the stream is in the same scope
as the time_facet instance, and thus making sure they are destroyed at
the same time.
Any idea why this is? Is this a bug, a feature, or am I being stupid again?
Greetz,
Mark