View Issue Details

IDProjectCategoryView StatusLast Update
0006355JEDI VCL00 JVCL Componentspublic2015-09-21 17:47
ReporterDavidVTaylorAssigned Toobones 
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.47 
Target VersionFixed in Version3.49 
Summary0006355: TJvHidDeviceController crash due to premature DLL unloading
DescriptionUsing multiple instance of the Hid Controller component in application results in an AV on shutdown:

Access violation at address 00000000. Read of address 00000000.

The AV occurs because TJvHidDeviceController.Destroy calls UnloadHid which causes the HID library to be prematurely unloaded. The first instance of the HID component unloads the DLL and the second instance crashes since the DLL procedure pointers have been invalidated.
Additional InformationThe solution to the problem was to add a counter to track calls to LoadHid/UnloadHid similar to the way LoadSetupApi/UnloadSetupApi works. The attached Hid.pas file implements this change and resolves the AV problem when using multiple HID components. Below are the changes made to the code:


var
  HidLib: TModuleHandle = INVALID_MODULEHANDLE_VALUE;
  HidLoadCount: Integer = 0; <- Added


function LoadHid: Boolean;
begin
  {$IFDEF HID_LINKONREQUEST}
  Inc(HidLoadCount); <- Added
  if HidLoadCount > 1 then <- Added
    Exit; <- Added
  Result := LoadModule(HidLib, HidModuleName);


procedure UnloadHid;
begin
  {$IFDEF HID_LINKONREQUEST}
  Dec(HidLoadCount); <- Added
  if HidLoadCount > 0 then <- Added
    Exit; <- Added
  UnloadModule(HidLib);

TagsNo tags attached.

Activities

2014-11-15 05:46

 

Hid.pas (118,850 bytes)

Issue History

Date Modified Username Field Change
2014-11-15 05:46 DavidVTaylor New Issue
2014-11-15 05:46 DavidVTaylor File Added: Hid.pas
2014-12-04 15:04 obones Status new => acknowledged
2014-12-04 15:53 obones Status acknowledged => resolved
2014-12-04 15:53 obones Fixed in Version => Daily / GIT
2014-12-04 15:53 obones Resolution open => fixed
2014-12-04 15:53 obones Assigned To => obones
2015-09-21 17:47 obones Fixed in Version Daily / GIT => 3.49