PDA

View Full Version : in new Thread, report this error "ECannotCreateWICImagingFactory"



devchenxip
20-06-2016, 10:21 AM
procedure TArchiveManager.loadImages(const pvPath: string);var
lvFileList: TStrings;
i: Integer;
lvKey: string;
begin
lvFileList:= TStringList.Create;
try
enumFileInRecursion(pvPath,lvFileList,'.png');
for i:= 0 to lvFileList.Count -1 do
begin
FLocker.lock();
try
lvKey:= ChangeFileExt(ExtractFileName(lvFileList[i]), '');
FEngineImages.AddFromFile(lvFileList[i],lvKey);
finally
FLocker.unLock;
end;
end;
finally
lvFileList.Free;
end;
end;


procedure onLoadGameData;
begin
gvArchiveManager.loadFiles('.\config','.aui,.amap' ,gvArchiveManager.FEngineConfigs);
sleep(1000);
gvArchiveManager.loadFiles('.\script','.lua',gvArc hiveManager.FEngineScripts);
sleep(1000);
gvArchiveManager.loadFiles('.\sound','.ogg,.wav',g vArchiveManager.FEngineSounds);
sleep(1000);
gvArchiveManager.loadFonts('.\font');
sleep(1000);
gvArchiveManager.loadImages('.\artres');


gvGameState:= tgsLoadingCompleted;
end;


procedure TArchiveManager.loadAll();
begin
TThread.CreateAnonymousThread(onLoadGameData).Star t;
end;

devchenxip
21-06-2016, 03:58 AM
onLoadGameData must call CoInitialize fix this error:
{$IFDEF MSWINDOWS}CoInitialize(nil);{$ENDIF}

LP
22-06-2016, 07:55 PM
Thanks for documenting this, but this is really how COM works when you use multi-threading, it doesn't look like something that can be done on PXL's side.

devchenxip
27-06-2016, 09:24 AM
Thanks for documenting this, but this is really how COM works when you use multi-threading(Main Thread Load Images, not found this error), it doesn't look like something that can be done on PXL's side.

Now,add "CoInitialize" and fixed "ECannotCreateWICImagingFactory". but, If use multi-threading, occasionally report new error "floating point divide by zero at 0x6be7464e". this error break to "FMX.Canvas.D2D.pas":


class function TBitmapCodecWIC.IsValid(const AStream: TStream): Boolean;
var
Decoder: IWICBitmapDecoder;
Frame: IWICBitmapFrameDecode;
W, H: UINT;
CopyStream: TMemoryStream;
Stream: IWICStream;
SavePosition: Int64;
begin
W := 0;
H := 0;
SavePosition := AStream.Position;
try
CopyStream := TMemoryStream.Create;
try
CopyStream.CopyFrom(AStream, AStream.Size);


ImagingFactory.CreateStream(Stream);
Stream.InitializeFromMemory(CopyStream.Memory, CopyStream.Size);


ImagingFactory.CreateDecoderFromStream(stream, GUID_NULL, WICDecodeMetadataCacheOnDemand, Decoder);
if Decoder <> nil then
begin
Decoder.GetFrame(0, Frame);
if Frame <> nil then
Frame.GetSize(W, H);
end;
Result := W * H <> 0;
finally
CopyStream.Free;
end;
finally
AStream.Position := SavePosition;
end;
end;


Stack sequence:
:6be7464e ; C:\Windows\SysWOW64\WindowsCodecs.dll
:6bee8413 ; C:\Windows\SysWOW64\WindowsCodecs.dll
:6bee747f ; C:\Windows\SysWOW64\WindowsCodecs.dll
:6be1a070 ; C:\Windows\SysWOW64\WindowsCodecs.dll
:6be1944e ; C:\Windows\SysWOW64\WindowsCodecs.dll
:6be13f1a ; C:\Windows\SysWOW64\WindowsCodecs.dll
FMX.Canvas.D2D.TBitmapCodecWIC.IsValid($26DB338)
FMX.Graphics.TBitmapCodecManager.LoadFromStream(?? ?,$C3DB6C0,0)
PXL.FMBridge.TFMBridge.LoadFromStream(nil,'.png',$ 26DB338,$A857720,DontCare)
PXL.ImageFormats.TImageFormatManager.LoadFromStrea m('.png',$26DB338,$A857720,DontCare)
PXL.Images.TAtlasImage.LoadFromStream('.png',$26DB 338,DontCare)
PXL.Images.TAtlasImages.AddFromStream('.png',$26DB 338,'item_e10050',True,DontCare,Unknown)
PXL.Images.TAtlasImages.AddFromFile('.\artres\item _e10050.png','item_e10050',True,DontCare,Unknown)
fol.client.archive.TFOLArchiveManager.loadImages(' .\artres')
fol.client.archive.onLoadGameData