mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
fix crash when querying game log before starting
This commit is contained in:
parent
aac9cb1e82
commit
daadba7e4e
@ -397,6 +397,10 @@ call_read_system_log(P3D_object *params[], int num_params) {
|
|||||||
P3D_object *P3DMainObject::
|
P3D_object *P3DMainObject::
|
||||||
read_log(const string &log_pathname, P3D_object *params[], int num_params) {
|
read_log(const string &log_pathname, P3D_object *params[], int num_params) {
|
||||||
ifstream log(log_pathname.c_str(), ios::in);
|
ifstream log(log_pathname.c_str(), ios::in);
|
||||||
|
if (!log) {
|
||||||
|
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
|
||||||
|
return inst_mgr->new_undefined_object();
|
||||||
|
}
|
||||||
|
|
||||||
// Check the parameter, if any--if specified, it specifies the last
|
// Check the parameter, if any--if specified, it specifies the last
|
||||||
// n bytes to retrieve.
|
// n bytes to retrieve.
|
||||||
@ -408,6 +412,7 @@ read_log(const string &log_pathname, P3D_object *params[], int num_params) {
|
|||||||
// Get the size of the file.
|
// Get the size of the file.
|
||||||
log.seekg(0, ios::end);
|
log.seekg(0, ios::end);
|
||||||
size_t size = (size_t)log.tellg();
|
size_t size = (size_t)log.tellg();
|
||||||
|
nout << "read_log: " << log_pathname << " is " << size << " bytes\n";
|
||||||
|
|
||||||
if (max_bytes > 0 && max_bytes < (int)size) {
|
if (max_bytes > 0 && max_bytes < (int)size) {
|
||||||
// Apply the limit.
|
// Apply the limit.
|
||||||
@ -418,6 +423,7 @@ read_log(const string &log_pathname, P3D_object *params[], int num_params) {
|
|||||||
log.seekg(0, ios::beg);
|
log.seekg(0, ios::beg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nout << "allocating " << size << " bytes to return.\n";
|
||||||
char *buffer = new char[size];
|
char *buffer = new char[size];
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user