Skip to content

image-source: Retry image load if not loaded - #8783

Closed
adampoit wants to merge 2 commits into
obsproject:masterfrom
adampoit:image-source-load-fix
Closed

adampoit wants to merge 2 commits into
obsproject:masterfrom
adampoit:image-source-load-fix

Conversation

@adampoit

Copy link
Copy Markdown

Description

Allows an image source to attempt another load, at the regular polling interval, even if the timestamp is unchanged. This handles situations where a previous load attempt may have failed, such as the file being locked by another process.

Motivation and Context

If an image source attempts to load an image and it fails, the image source will never reattempt to load the image until the file timestamp changes.

I came across this issue when using an external program to update images for my stream. I noticed that occasionally an image update would coincide with the image not showing in OBS. I dug into the logs and noticed the following entries:

19:48:23.144: Failed to open file 'C:/Users/.../rightSongMetadata.png': Permission denied
19:48:23.145: WIC: Failed to create IWICBitmapDecoder from file: C:/Users/.../rightSongMetadata.png
19:48:23.145: gs_image_file_init_internal: Failed to load file 'C:/Users/.../rightSongMetadata.png'
19:48:23.145: [image_source: 'Right Song'] failed to load texture 'C:/Users/.../rightSongMetadata.png'

Upon further investigation, I saw this problem described in this issue comment. While I could not recreate the text source problem described in the original issue, I was able to consistently reproduce the problem with an image source.

How Has This Been Tested?

I tested on Windows 11 using the following PowerShell script:

param([bool] $lock)

$source = Join-Path $PSScriptRoot "example1.jpg"
$target = Join-Path $PSScriptRoot "example.jpg"

Remove-Item $target -Force
Start-Sleep -Milliseconds 1500
Copy-Item $source $target -Force
if ($lock)
{
	Write-Host "Locking $target"
	$fileStream = New-Object IO.FileStream($target, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)
	Start-Sleep -Milliseconds 1500
	$fileStream.Close()
	Write-Host "Lock released"
}

If I ran the script with -lock $true, I was able to consistently reproduce the issue. The lock parameter was included in the script so I could easily reset the test.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@adampoit

adampoit commented Apr 21, 2023 •

Copy link
Copy Markdown
Author

The downside with this approach is that the image will "blip out" for the duration of the polling interval. The result is still better than what we have now, where the image will never attempt to load again.

The ideal fix would be to avoid unloading the currently displayed image until a successful load has occurred. I have attempted to make that change here: adampoit@6da8ee4.

I'm happy to go either direction, but my original proposal seemed like the path of least resistance. Allocating a temp struct and using memmove seems like a higher bar to justify.

Comment thread plugins/image-source/image-source.c Resolved
@RytoEX RytoEX added the kind/bug Categorizes issue or PR as related to a bug. label Apr 22, 2023
adampoit added 2 commits June 6, 2023 10:46
Allows an image source to attempt another load, at the regular polling
interval, even if the timestamp is unchanged. This handles situations
where a previous load attempt may have failed, such as the file being
locked by another process.
@adampoit
adampoit force-pushed the image-source-load-fix branch from 76f0830 to 11a4386 Compare June 6, 2023 17:47
@PatTheMav

Copy link
Copy Markdown
Member

I guess the underlying root issue is that Windows has mandatory file locks (POSIX commonly doesn't use them) and if a file is locked one cannot even get the modification timestamp?

Because on POSIX systems the modification timestamp only changes if the actual file is renamed, which then also updates context->file_timestamp and once the file becomes available again, the actual timestamp will be different to -1 and the file appears again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Categorizes issue or PR as related to a bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants