Repository navigation
Conversation
The x64 configurations link libusbK\x64\libusbk.lib, but the repo only has the x86 libusbK.lib: .gitignore excludes every x64/ folder, so the x64 copy was never committed and Release|x64 fails to link (LNK1181). Generate it from the x86 library's export list (libusbK.def, 107 undecorated exports; libusbK.dll exports the same names on both architectures) with "lib /def:libusbK.def /machine:x64 /out:x64\libusbk.lib", and add a .gitignore exception for that folder.
Unplugging the camera (or it dropping off USB on its own) during a session crashed or froze the host (seen with N.I.N.A.). Fixes, by area: Crashes - DeviceEventHandler::OnEvent released an uninitialised IPortableDevicePropVariantCollection pointer when an event has no MTP parameters (e.g. Device Removed): AV on the WPD callback thread. - The event handler was deleted while WPD still held references, and kept a raw Camera* after close. It is now reference counted, registered/unregistered explicitly (per-instance cookie instead of a global), ignores events once unregistered, and the camera waits for in-flight callbacks before deletion. - Exported functions used a null Camera* for stale or already-closed handles (double CloseDevice). They now return ERROR_INVALID_HANDLE, and closes are serialised. - CameraTask::Start created its completion semaphore already signalled, so Cancel() never waited and StartCapture/CancelCapture deleted tasks the worker was still running (use-after-free in CameraTask::Step). The semaphore now starts unsignalled, tasks are deleted only after the worker finishes them, and are waited for outside m_hBusyMutex. - Image-ready events replaced m_downloadAndProcessImageTask without a lock; duplicate notifications are now ignored while a download exists. Hangs - downloadImage looped forever when GetImage failed (imageReady was never updated), blocking the worker so CloseDevice never returned. Now limited to 5 attempts, and the capture is reported as failed. - StartCapture's previous-photo wait was endless: "WORD x = a != 0" assigns the comparison, and the loop re-read a stale settings copy. It now re-reads the live status with a timeout and then proceeds. - CreateCamera registered a camera whose open failed (still unplugged) under handle 0xFFFFFFFF, which is not INVALID_HANDLE_VALUE on x64; OpenDevice then initialised it and waited forever. Failed opens are no longer registered. - After a mid-exposure unplug an ILCE-7M3 reports photo buffer status 0x0001 (processing) indefinitely while still shooting normally; the wait for it is short and is skipped once seen stuck. Disconnect detection - WPD only reports Device Removed on the next device I/O (possibly the end of a long exposure). Removal is also watched with CM_Register_Notification on the device interface, so it is seen as soon as the cable is pulled. - On removal the current capture is reported as failed at once, and starts, downloads and exposure waits stop immediately instead of timing out. Camera stability - Two threads could interleave MTP transfers (StartCapture discarding a waiting photo and a worker download), which made the camera drop off USB. MTP transactions are now serialised per device. - Image-ready events are ignored from the start of StartCapture until the shutter is released: fetching a photo while the camera processes a shot resets an ILCE-7M3's USB. - Camera::GetImage leaked ObjectInfo on failure; OpenDeviceEx's exception path removed the wrong camera entry. Tested on an ILCE-7M3 with N.I.N.A. 3.2: manual and natural USB drops recover without crashing, and a 7.7-hour run (7,790 exposures) had no disconnects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a Sony camera is unplugged during a session, or drops off USB on its own, the driver currently crashes or freezes the host application. I hit this with an ILCE-7M3 in N.I.N.A. 3.2 (crash dump: AV at
SonyMTPCamera.dll+0x234B7on the WPD event thread, 1.0.1.21). While fixing it I found a chain of related problems on the removal and recovery paths. This PR fixes them so the host can close and reopen the camera after a drop and carry on.Base:
workerThread@ 21f469f (1.0.1.21).Commits
.gitignoreexcludesx64/, solibusbK\x64\libusbk.libwas never committed and Release|x64 doesn't link. It's generated from the x86 export list (libusbK.def), with a.gitignoreexception for that folder.Crashes
DeviceEventHandler::OnEventreleased an uninitialisedIPortableDevicePropVariantCollection*when an event carries no MTP parameters (e.g. Device Removed). This is the original crash.Camera*after close. It's now reference counted, explicitly (un)registered with a per-instance cookie, and inert after unregistering, and the camera drains in-flight callbacks before deletion.Camera*for stale or already-closed handles (a host callingCloseDevicetwice). They now returnERROR_INVALID_HANDLE, and closes are serialised.CameraTask::Startcreated its completion semaphore already signalled, soCancel()never waited, andStartCapture/CancelCapturedeleted tasks the worker was still running (use-after-free inCameraTask::Step).m_downloadAndProcessImageTaskwithout a lock.Hangs
downloadImagelooped forever whenGetImagefailed, blocking the worker soCloseDevicenever returned.StartCapture's previous-photo wait could never exit.while (WORD s = x->GetUINT16() != 0)assigns the comparison, and the loop re-read a stale settings copy.CreateCameraregistered a camera whose open failed (still unplugged) under handle0xFFFFFFFF, which isn'tINVALID_HANDLE_VALUEon x64, soOpenDevicethen waited forever initialising it.Detection and stability
CM_Register_Notification, and pending captures fail immediately.StartCaptureuntil the shutter is released. Fetching a photo while an ILCE-7M3 is processing a shot resets its USB.Camera behaviour worth knowing (ILCE-7M3)
0x0001(processing) until the camera is power-cycled, while photos are still taken and delivered normally. The wait for it is now short, and skipped once it's seen stuck.Testing
Relation to other open PRs
MTPDevice.cpp,Camera.cpp,Device.h) and will conflict. This PR covers that ground differently (Plug and Play notification plus refcounted handler) and also fixes the crashes, hangs and races above. I'm happy to rebase onto Stop talking to a camera that Windows has taken away #16 if you'd prefer to take it first, or the other way round.2 ^ 23) is independent and doesn't overlap.