fixed crash when a mesh lit by a point light is reloaded

This commit is contained in:
Mikulas Florek 2016-02-27 22:38:35 +01:00
parent 4181bf0fb5
commit 970193103f
3 changed files with 58 additions and 35 deletions

View file

@ -2093,40 +2093,37 @@ void ImportAssetDialog::onGUI()
ImGui::Checkbox("Make convex", &m_make_convex);
}
if (scene->mNumMeshes > 1)
if (ImGui::CollapsingHeader(
StringBuilder<30>("Meshes (") << scene->mNumMeshes << ")###Meshes",
nullptr,
true,
true))
{
if (ImGui::CollapsingHeader(
StringBuilder<30>("Meshes (") << scene->mNumMeshes << ")###Meshes",
nullptr,
true,
true))
if (ImGui::Button("Select all"))
{
if (ImGui::Button("Select all"))
{
for (int i = 0; i < m_mesh_mask.size(); ++i) m_mesh_mask[i] = true;
}
for (int i = 0; i < m_mesh_mask.size(); ++i) m_mesh_mask[i] = true;
}
ImGui::SameLine();
if (ImGui::Button("Deselect all"))
{
for (int i = 0; i < m_mesh_mask.size(); ++i) m_mesh_mask[i] = false;
}
for (int i = 0; i < (int)scene->mNumMeshes; ++i)
{
if (!scene->mMeshes[i]->mTangents) continue;
const char* name = scene->mMeshes[i]->mName.C_Str();
if (name[0] == 0) name = ConvertTask::getMeshName(scene, scene->mMeshes[i]).C_Str();
bool b = m_mesh_mask[i];
auto* material = scene->mMaterials[scene->mMeshes[i]->mMaterialIndex];
aiString material_name;
material->Get(AI_MATKEY_NAME, material_name);
ImGui::Checkbox(StringBuilder<30>(name[0] == 0 ? material_name.C_Str() : name,
"###mesh",
(Lumix::uint64)&scene->mMeshes[i]),
&b);
ImGui::SameLine();
if (ImGui::Button("Deselect all"))
{
for (int i = 0; i < m_mesh_mask.size(); ++i) m_mesh_mask[i] = false;
}
for (int i = 0; i < (int)scene->mNumMeshes; ++i)
{
if (!scene->mMeshes[i]->mTangents) continue;
const char* name = scene->mMeshes[i]->mName.C_Str();
if (name[0] == 0) name = ConvertTask::getMeshName(scene, scene->mMeshes[i]).C_Str();
bool b = m_mesh_mask[i];
auto* material = scene->mMaterials[scene->mMeshes[i]->mMaterialIndex];
aiString material_name;
material->Get(AI_MATKEY_NAME, material_name);
ImGui::Checkbox(StringBuilder<30>(name[0] == 0 ? material_name.C_Str() : name,
"###mesh",
(Lumix::uint64)&scene->mMeshes[i]),
&b);
ImGui::SameLine();
ImGui::Text(" - material: %s", material_name.C_Str());
m_mesh_mask[i] = b;
}
ImGui::Text(" - material: %s", material_name.C_Str());
m_mesh_mask[i] = b;
}
}

View file

@ -1,5 +1,6 @@
#include "lumix.h"
#include "core/crc32.h"
#include "core/FS/disk_file_device.h"
#include "core/FS/file_system.h"
#include "core/json_serializer.h"
#include "core/log.h"
@ -70,13 +71,33 @@ struct MaterialPlugin : public AssetBrowser::IPlugin
*file, JsonSerializer::AccessMode::WRITE, material->getPath(), allocator);
if (!material->save(serializer))
{
g_log_error.log("Editor") << "Error saving "
<< material->getPath().c_str();
g_log_error.log("Editor") << "Error saving " << material->getPath().c_str();
}
fs.close(*file);
PlatformInterface::deleteFile(material->getPath().c_str());
PlatformInterface::moveFile(tmp_path, material->getPath().c_str());
StringBuilder<Lumix::MAX_PATH_LENGTH> src_full_path(
m_app.getWorldEditor()->getEngine().getDiskFileDevice()->getBasePath(0));
StringBuilder<Lumix::MAX_PATH_LENGTH> dest_full_path(
m_app.getWorldEditor()->getEngine().getDiskFileDevice()->getBasePath(0));
src_full_path << tmp_path;
dest_full_path << material->getPath().c_str();
if (!PlatformInterface::fileExists(src_full_path))
{
src_full_path.data[0] = 0;
dest_full_path.data[0] = 0;
src_full_path << m_app.getWorldEditor()->getEngine().getDiskFileDevice()->getBasePath(1);
src_full_path << tmp_path;
dest_full_path << m_app.getWorldEditor()->getEngine().getDiskFileDevice()->getBasePath(1);
dest_full_path << material->getPath().c_str();
}
PlatformInterface::deleteFile(dest_full_path);
if (!PlatformInterface::moveFile(src_full_path, dest_full_path))
{
g_log_error.log("Editor") << "Could not save file "
<< material->getPath().c_str();
}
}
else
{

View file

@ -2948,6 +2948,11 @@ public:
LUMIX_DELETE(m_allocator, r.pose);
r.pose = nullptr;
for (int i = 0; i < m_point_lights.size(); ++i)
{
PointLight& light = m_point_lights[i];
m_light_influenced_geometry[i].eraseItemFast(component);
}
m_culling_system->removeStatic(component);
}