Properly wait while resource is pending in ResourceManager
This commit is contained in:
parent
4a6e086c0e
commit
ea46b48eee
@ -196,7 +196,7 @@ polygun::renderer::Surface& ResourceManager::get_surface(const std::string& reso
|
||||
}
|
||||
|
||||
// Check if resource is loaded
|
||||
if(m_textures.count(resource_id)) {
|
||||
if(m_surfaces.count(resource_id)) {
|
||||
LoadedResource<renderer::Surface>& resource = m_surfaces[resource_id];
|
||||
resource.m_last_used = std::chrono::steady_clock::now();
|
||||
release();
|
||||
|
@ -79,6 +79,19 @@ void TextureAtlas::construct_thread_func() {
|
||||
std::string texture_filename = m_content_registry.get_node_def(i).m_texture_filename;
|
||||
if(texture_filename.empty())
|
||||
continue;
|
||||
|
||||
m_resource_manager.get_surface(texture_filename);
|
||||
|
||||
const std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
|
||||
while(m_resource_manager.is_pending()) {
|
||||
const std::chrono::time_point<std::chrono::system_clock> tm = std::chrono::system_clock::now();
|
||||
const std::chrono::duration<double> interval = tm-start;
|
||||
if(interval.count()>30) {
|
||||
LOG_WARNING("Waiting for node texture '%s' took too long, stopping", texture_filename.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
renderer::Surface& surf = m_resource_manager.get_surface(texture_filename);
|
||||
surfaces[i-1] = &surf;
|
||||
if(surf.get_width()>max_texture_width)
|
||||
@ -86,15 +99,6 @@ void TextureAtlas::construct_thread_func() {
|
||||
if(surf.get_height()>max_texture_height)
|
||||
max_texture_height = surf.get_height();
|
||||
}
|
||||
const std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
|
||||
while(m_resource_manager.is_pending()) {
|
||||
const std::chrono::time_point<std::chrono::system_clock> tm = std::chrono::system_clock::now();
|
||||
const std::chrono::duration<double> interval = tm-start;
|
||||
if(interval.count()>30) {
|
||||
LOG_WARNING("Waiting for node textures took too long, stopping");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
acquire();
|
||||
m_atlas_surface.reset(new renderer::Surface(max_texture_width*surface_count, max_texture_height));
|
||||
|
Loading…
x
Reference in New Issue
Block a user