Fix DialogBrowse crashing when deleting the last item nullptr. In iOS use std::recursive_mutex instead of the custom check.
This commit is contained in:
@@ -39,23 +39,26 @@ int t_count = 0;
|
||||
glm::vec2 t_pos;
|
||||
int lock_count = 0;
|
||||
NSThread* lock_thread;
|
||||
std::recursive_mutex lock_mutex;
|
||||
|
||||
@implementation GameViewController
|
||||
- (void)async_lock
|
||||
{
|
||||
if (lock_thread != [NSThread currentThread] || lock_count == 0)
|
||||
[gl_lock lock];
|
||||
lock_thread = [NSThread currentThread];
|
||||
lock_count++;
|
||||
lock_mutex.lock();
|
||||
// if (lock_thread != [NSThread currentThread] || lock_count == 0)
|
||||
// [gl_lock lock];
|
||||
// lock_thread = [NSThread currentThread];
|
||||
// lock_count++;
|
||||
[EAGLContext setCurrentContext:self.context];
|
||||
GLKView* view = (GLKView*)self.view;
|
||||
[view bindDrawable];
|
||||
}
|
||||
- (void)async_unlock
|
||||
{
|
||||
lock_count--;
|
||||
if (lock_count == 0)
|
||||
[gl_lock unlock];
|
||||
// lock_count--;
|
||||
// if (lock_count == 0)
|
||||
// [gl_lock unlock];
|
||||
lock_mutex.unlock();
|
||||
}
|
||||
- (void)async_swap
|
||||
{
|
||||
|
||||
@@ -1530,11 +1530,30 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
|
||||
// static char name[128];
|
||||
// sprintf(name, "%s/latlong.ppi", data_path.c_str());
|
||||
FILE* fp = fopen(file_path.c_str(), "wb");
|
||||
if (!fp)
|
||||
FILE* fp;
|
||||
|
||||
std::string tmp_path = file_path.substr(0, file_path.size() - strlen(".ppi")) + ".tmp.ppi";
|
||||
bool use_tmp = false;
|
||||
// check if file already exists
|
||||
if ((fp = fopen(file_path.c_str(), "rb")))
|
||||
{
|
||||
LOG("cannot write project to %s", file_path.c_str());
|
||||
return;
|
||||
fclose(fp);
|
||||
// use tmp file for writing
|
||||
use_tmp = true;
|
||||
if (!(fp = fopen(tmp_path.c_str(), "wb")))
|
||||
{
|
||||
LOG("cannot write project to %s", file_path.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// write directly to the new file
|
||||
if (!(fp = fopen(file_path.c_str(), "wb")))
|
||||
{
|
||||
LOG("cannot write project to %s", file_path.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PPIHeader ppi_header;
|
||||
@@ -1601,7 +1620,7 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
};
|
||||
int ret = stbi_write_png_to_func(callback, &compressed, sz.x, sz.y, 4, snap.image[plane_index].get(), sz.x * 4);
|
||||
|
||||
int data_size = compressed.size();
|
||||
int data_size = (int)compressed.size();
|
||||
fwrite(&data_size, sizeof(int), 1, fp);
|
||||
|
||||
fwrite(compressed.data(), 1, compressed.size(), fp);
|
||||
@@ -1616,10 +1635,30 @@ void ui::Canvas::project_save_thread(std::string file_path)
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
LOG("project saved to %s", file_path.c_str());
|
||||
|
||||
// App::I.upload(data_path);
|
||||
// LOG("uploaded");
|
||||
if (use_tmp)
|
||||
{
|
||||
LOG("project saved tmp to %s", tmp_path.c_str());
|
||||
LOG("swapping to %s", file_path.c_str());
|
||||
if (std::remove(file_path.c_str()) == 0)
|
||||
{
|
||||
if (std::rename(tmp_path.c_str(), file_path.c_str()) == 0)
|
||||
{
|
||||
LOG("tmp file swapped succesfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("tmp file NOT swapped, original removed");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("could not remove %s", file_path.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("project saved to %s", file_path.c_str());
|
||||
}
|
||||
|
||||
m_unsaved = false;
|
||||
m_newdoc = false;
|
||||
|
||||
@@ -47,6 +47,8 @@ void NodeDialogBrowse::init_controls()
|
||||
msgbox->btn_ok->on_click = [this,msgbox](Node*){
|
||||
auto path = current->m_path;
|
||||
int idx = container->get_child_index(current);
|
||||
if (auto image_tex = current->find<NodeImageTexture>("thumb-tex"))
|
||||
image_tex->tex.destroy();
|
||||
container->remove_child(current);
|
||||
if (!container->m_children.empty())
|
||||
{
|
||||
@@ -59,8 +61,6 @@ void NodeDialogBrowse::init_controls()
|
||||
else
|
||||
{
|
||||
current = nullptr;
|
||||
auto image_tex = find<NodeImageTexture>("thumb-tex");
|
||||
image_tex->tex.destroy();
|
||||
}
|
||||
Asset::delete_file(path);
|
||||
msgbox->destroy();
|
||||
@@ -94,10 +94,11 @@ void NodeDialogBrowse::init_controls()
|
||||
};
|
||||
|
||||
// load thumb
|
||||
auto image_tex = node->find<NodeImageTexture>("thumb-tex");
|
||||
image_tex->tex.destroy();
|
||||
image_tex->tex.create(thumb);
|
||||
|
||||
if (auto image_tex = node->find<NodeImageTexture>("thumb-tex"))
|
||||
{
|
||||
image_tex->tex.destroy();
|
||||
image_tex->tex.create(thumb);
|
||||
}
|
||||
container->add_child(node);
|
||||
}
|
||||
// if (auto* first = (NodeDialogBrowseItem*)container->get_child_at(0))
|
||||
|
||||
Reference in New Issue
Block a user