Don't reload editor preview image every frame if it's invalid

If the preview image in the "Add image" dialog could not be loaded it was retried every frame, which causes a debug message to be printed each time.

Now a tristate variable is used to ensure that the image is not reloaded after is previously failed to load.
This commit is contained in:
Robert Müller 2023-03-17 12:31:02 +01:00
parent 0c67d033ea
commit 9b8d8e4965
2 changed files with 19 additions and 8 deletions

View file

@ -4891,7 +4891,7 @@ void CEditor::RenderFileDialog()
if(m_FilesSelectedIndex > -1)
{
if(m_FileDialogFileType == CEditor::FILETYPE_IMG && !m_PreviewImageIsLoaded && m_FilesSelectedIndex > -1)
if(m_FileDialogFileType == CEditor::FILETYPE_IMG && m_PreviewImageState == PREVIEWIMAGE_UNLOADED && m_FilesSelectedIndex > -1)
{
if(str_endswith(m_vpFilteredFileList[m_FilesSelectedIndex]->m_aFilename, ".png"))
{
@ -4902,11 +4902,15 @@ void CEditor::RenderFileDialog()
Graphics()->UnloadTexture(&m_FilePreviewImage);
m_FilePreviewImage = Graphics()->LoadTextureRaw(m_FilePreviewImageInfo.m_Width, m_FilePreviewImageInfo.m_Height, m_FilePreviewImageInfo.m_Format, m_FilePreviewImageInfo.m_pData, m_FilePreviewImageInfo.m_Format, 0);
Graphics()->FreePNG(&m_FilePreviewImageInfo);
m_PreviewImageIsLoaded = true;
m_PreviewImageState = PREVIEWIMAGE_LOADED;
}
else
{
m_PreviewImageState = PREVIEWIMAGE_ERROR;
}
}
}
if(m_FileDialogFileType == CEditor::FILETYPE_IMG && m_PreviewImageIsLoaded)
if(m_FileDialogFileType == CEditor::FILETYPE_IMG && m_PreviewImageState == PREVIEWIMAGE_LOADED)
{
int w = m_FilePreviewImageInfo.m_Width;
int h = m_FilePreviewImageInfo.m_Height;
@ -4992,7 +4996,7 @@ void CEditor::RenderFileDialog()
str_copy(m_aFileDialogFileName, m_vpFilteredFileList[m_FilesSelectedIndex]->m_aFilename);
else
m_aFileDialogFileName[0] = '\0';
m_PreviewImageIsLoaded = false;
m_PreviewImageState = PREVIEWIMAGE_UNLOADED;
}
// the buttons
@ -5166,7 +5170,7 @@ void CEditor::FilelistPopulate(int StorageType, bool KeepSelection)
else
m_aFilesSelectedName[0] = '\0';
}
m_PreviewImageIsLoaded = false;
m_PreviewImageState = PREVIEWIMAGE_UNLOADED;
}
void CEditor::InvokeFileDialog(int StorageType, int FileType, const char *pTitle, const char *pButtonText,
@ -5185,7 +5189,7 @@ void CEditor::InvokeFileDialog(int StorageType, int FileType, const char *pTitle
m_aFileDialogCurrentLink[0] = 0;
m_pFileDialogPath = m_aFileDialogCurrentFolder;
m_FileDialogFileType = FileType;
m_PreviewImageIsLoaded = false;
m_PreviewImageState = PREVIEWIMAGE_UNLOADED;
m_FileDialogOpening = true;
if(pDefaultName)

View file

@ -747,6 +747,13 @@ class CEditor : public IEditor
int GetTextureUsageFlag();
enum EPreviewImageState
{
PREVIEWIMAGE_UNLOADED,
PREVIEWIMAGE_LOADED,
PREVIEWIMAGE_ERROR,
};
public:
class IInput *Input() { return m_pInput; }
class IClient *Client() { return m_pClient; }
@ -808,7 +815,7 @@ public:
m_FilesSelectedIndex = -1;
m_FilePreviewImage.Invalidate();
m_PreviewImageIsLoaded = false;
m_PreviewImageState = PREVIEWIMAGE_UNLOADED;
m_SelectEntitiesImage = "DDNet";
@ -979,7 +986,7 @@ public:
int m_FilesSelectedIndex;
char m_aFileDialogNewFolderName[IO_MAX_PATH_LENGTH];
IGraphics::CTextureHandle m_FilePreviewImage;
bool m_PreviewImageIsLoaded;
EPreviewImageState m_PreviewImageState;
CImageInfo m_FilePreviewImageInfo;
bool m_FileDialogOpening;