Skip to content

Commit dbded92

Browse files
committed
Add more null checks
1 parent 74b32bb commit dbded92

4 files changed

Lines changed: 55 additions & 46 deletions

File tree

apps/mapeditor/src/mainwindow.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,29 +212,32 @@ void MainWindow::openMap(const QString &basePath, const int territoryType, const
212212
if (contentFinderCondition != 0) {
213213
qInfo() << "This map contains a duty! CF:" << contentFinderCondition;
214214

215-
auto cfcExh = physis_exh_parse(m_cache.platform(), m_cache.read(QStringLiteral("exd/ContentFinderCondition.exh")));
216-
if (cfcExh.p_ptr) {
217-
auto cfcSheet = m_cache.readExcelSheet(QStringLiteral("ContentFinderCondition"), &cfcExh, getLanguage());
215+
const auto buffer = m_cache.read(QStringLiteral("exd/ContentFinderCondition.exh"));
216+
if (buffer.size > 0) {
217+
const auto cfcExh = physis_exh_parse(m_cache.platform(), buffer);
218+
if (cfcExh.p_ptr) {
219+
auto cfcSheet = m_cache.readExcelSheet(QStringLiteral("ContentFinderCondition"), &cfcExh, getLanguage());
218220

219-
auto cfcRow = physis_excel_get_row(&cfcSheet, contentFinderCondition);
220-
auto instanceContentId = cfcRow.columns[3].u_int16._0;
221+
auto cfcRow = physis_excel_get_row(&cfcSheet, contentFinderCondition);
222+
auto instanceContentId = cfcRow.columns[3].u_int16._0;
221223

222-
auto instanceContentExh = physis_exh_parse(m_cache.platform(), m_cache.read(QStringLiteral("exd/InstanceContent.exh")));
223-
auto instanceContentSheet = m_cache.readExcelSheet(QStringLiteral("InstanceContent"), &instanceContentExh, Language::None);
224+
auto instanceContentExh = physis_exh_parse(m_cache.platform(), m_cache.read(QStringLiteral("exd/InstanceContent.exh")));
225+
auto instanceContentSheet = m_cache.readExcelSheet(QStringLiteral("InstanceContent"), &instanceContentExh, Language::None);
224226

225-
auto instanceContentRow = physis_excel_get_row(&instanceContentSheet, instanceContentId);
227+
auto instanceContentRow = physis_excel_get_row(&instanceContentSheet, instanceContentId);
226228

227-
m_lgbEventRange = instanceContentRow.columns[7].u_int32._0;
229+
m_lgbEventRange = instanceContentRow.columns[7].u_int32._0;
228230

229-
auto mapEffectId = instanceContentRow.columns[64].u_int16._0;
231+
auto mapEffectId = instanceContentRow.columns[64].u_int16._0;
230232

231-
auto mapEffectExh = physis_exh_parse(m_cache.platform(), m_cache.read(QStringLiteral("exd/ContentDirectorManagedSG.exh")));
232-
auto mapEffectSheet = m_cache.readExcelSheet(QStringLiteral("ContentDirectorManagedSG"), &mapEffectExh, Language::None);
233+
auto mapEffectExh = physis_exh_parse(m_cache.platform(), m_cache.read(QStringLiteral("exd/ContentDirectorManagedSG.exh")));
234+
auto mapEffectSheet = m_cache.readExcelSheet(QStringLiteral("ContentDirectorManagedSG"), &mapEffectExh, Language::None);
233235

234-
auto effectCount = physis_excel_get_subrow_count(&mapEffectSheet, mapEffectId);
235-
for (size_t i = 0; i < effectCount; i++) {
236-
auto effectRow = physis_excel_get_subrow(&mapEffectSheet, mapEffectId, i);
237-
m_mapEffects.push_back(effectRow.columns[0].int32._0);
236+
auto effectCount = physis_excel_get_subrow_count(&mapEffectSheet, mapEffectId);
237+
for (size_t i = 0; i < effectCount; i++) {
238+
auto effectRow = physis_excel_get_subrow(&mapEffectSheet, mapEffectId, i);
239+
m_mapEffects.push_back(effectRow.columns[0].int32._0);
240+
}
238241
}
239242
}
240243
}

parts/scene/mapview.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,18 +379,18 @@ void MapView::updateLightCulling()
379379
for (auto &light : m_mdlPart->manager()->scene.lights) {
380380
// Update based on culling
381381
if (light.id != 0) {
382-
auto bounding_box = m_appState->checkLightBoundingBox(light.id, light.parentSgbId).value();
383-
bounding_box.min[0] += light.position[0];
384-
bounding_box.min[1] += light.position[1];
385-
bounding_box.min[2] += light.position[2];
386-
bounding_box.max[0] += light.position[0];
387-
bounding_box.max[1] += light.position[1];
388-
bounding_box.max[2] += light.position[2];
389-
if (m_mdlPart->manager()->scene.frustumCulling && !test_aabb_frustum(m_mdlPart->manager()->camera.frustum(), bounding_box)) {
390-
light.active = false;
391-
m_mdlPart->manager()->scene.culledLights++;
392-
break;
393-
} else {
382+
if (auto bounding_box = m_appState->checkLightBoundingBox(light.id, light.parentSgbId)) {
383+
bounding_box->min[0] += light.position[0];
384+
bounding_box->min[1] += light.position[1];
385+
bounding_box->min[2] += light.position[2];
386+
bounding_box->max[0] += light.position[0];
387+
bounding_box->max[1] += light.position[1];
388+
bounding_box->max[2] += light.position[2];
389+
if (m_mdlPart->manager()->scene.frustumCulling && !test_aabb_frustum(m_mdlPart->manager()->camera.frustum(), *bounding_box)) {
390+
light.active = false;
391+
m_mdlPart->manager()->scene.culledLights++;
392+
break;
393+
}
394394
light.active = true;
395395
}
396396
} else {

parts/scene/scenestate.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,37 +409,43 @@ std::optional<BoundingBox> SceneState::checkLightBoundingBox(const uint32_t id,
409409

410410
QString SceneState::lookupENpcName(const uint32_t id) const
411411
{
412-
auto row = physis_excel_get_row(&m_enpcResidentSheet, id);
413-
if (row.columns && strlen(row.columns[0].string._0) > 0) {
414-
QString name = QString::fromLatin1(row.columns[0].string._0);
412+
if (m_enpcResidentSheet.p_ptr) {
413+
auto row = physis_excel_get_row(&m_enpcResidentSheet, id);
414+
if (row.columns && strlen(row.columns[0].string._0) > 0) {
415+
QString name = QString::fromLatin1(row.columns[0].string._0);
416+
physis_free_row(&row, m_enpcResidentSheet.pages[0].column_count);
417+
return name;
418+
}
415419
physis_free_row(&row, m_enpcResidentSheet.pages[0].column_count);
416-
return name;
417420
}
418-
physis_free_row(&row, m_enpcResidentSheet.pages[0].column_count);
419421
return i18n("Event NPC");
420422
}
421423

422424
QString SceneState::lookupEObjName(const uint32_t id) const
423425
{
424-
auto row = physis_excel_get_row(&m_eobjNameSheet, id);
425-
if (row.columns && strlen(row.columns[0].string._0) > 0) {
426-
QString name = QString::fromLatin1(row.columns[0].string._0);
426+
if (m_eobjNameSheet.p_ptr) {
427+
auto row = physis_excel_get_row(&m_eobjNameSheet, id);
428+
if (row.columns && strlen(row.columns[0].string._0) > 0) {
429+
QString name = QString::fromLatin1(row.columns[0].string._0);
430+
physis_free_row(&row, m_eobjNameSheet.pages[0].column_count);
431+
return name;
432+
}
427433
physis_free_row(&row, m_eobjNameSheet.pages[0].column_count);
428-
return name;
429434
}
430-
physis_free_row(&row, m_eobjNameSheet.pages[0].column_count);
431435
return i18n("Event Object");
432436
}
433437

434438
QString SceneState::lookupBNpcName(uint32_t id) const
435439
{
436-
auto row = physis_excel_get_row(&m_bnpcNameSheet, id);
437-
if (row.columns && strlen(row.columns[0].string._0) > 0) {
438-
QString name = QString::fromLatin1(row.columns[0].string._0);
440+
if (m_bnpcNameSheet.p_ptr) {
441+
auto row = physis_excel_get_row(&m_bnpcNameSheet, id);
442+
if (row.columns && strlen(row.columns[0].string._0) > 0) {
443+
QString name = QString::fromLatin1(row.columns[0].string._0);
444+
physis_free_row(&row, m_bnpcNameSheet.pages[0].column_count);
445+
return name;
446+
}
439447
physis_free_row(&row, m_bnpcNameSheet.pages[0].column_count);
440-
return name;
441448
}
442-
physis_free_row(&row, m_bnpcNameSheet.pages[0].column_count);
443449
return i18n("Battle NPC");
444450
}
445451

parts/scene/scenestate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ class SceneState : public QObject
178178
void processUpdateAnimation(ObjectScene &scene, float time);
179179
void showAllInScene(const ObjectScene &scene);
180180

181-
physis_ExcelSheet m_enpcResidentSheet;
182-
physis_ExcelSheet m_eobjNameSheet;
183-
physis_ExcelSheet m_bnpcNameSheet;
181+
physis_ExcelSheet m_enpcResidentSheet{};
182+
physis_ExcelSheet m_eobjNameSheet{};
183+
physis_ExcelSheet m_bnpcNameSheet{};
184184
float m_longestAnimationTime = 0.0f;
185185
FileCache &m_cache;
186186
};

0 commit comments

Comments
 (0)