v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"  SOLVED

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Support,

This is an unfortunate topic that will probably be hard to mark as "solved" - I am only hoping you are already aware of the issue.

Please take the time to read in detail...

I've moved from 8.343 to 9.351. At first things seemed to run faster, some issues seems to be solved (like deadlocks in running IOperation) - and I was quite happy with 9.351 - with new stuff added and how it works in general.

Until I realized something has gone very wrong -> my app started crashing with no warnings for no particular reason and in "random" occasions.

Note: I am using the SDK in a rather complex way: I have my own classes implementing IOperation. I'm heavily using AsyncDo along with ThreadSafeCall. I'm creating my own Panes (both within MainFrame and DocumentView). I'm implemetning IUIX_TreeCallbacks, IUIX_ListCallbacks, IPXV_DocInfoBarCallbacks and so on. I'm instantiating multiple PXVControl instances - applying various custom CMD bars, hiding/disabling/custom handling some stuff, per control, etc... In short: I'm not using the SDK in a "hello world" fashion. For comparison: the "Full Demo" would be a "non trivial hello world" application.

With 8.343 - everything that I do with the SDK works with no issues.

With 9.351 - after processing some "heavy" code (AsyncDo and alike) and then trying to create a form hosting PXV Control (that is instantiate a new PXV Control) - the app crashes. I have exception handling mechanism, so my application can catch unhandled exceptions. In this case, nothing is caught - the app just vanishes.

When testing I'm making sure my code is 100% completely the same - so I am quite certain the cause of the crash is not within my code. I've recompiled my application several times with 8.343 and then 9.351 - the problem always appears only with 9.351.

The only trace of the crash can be found in Windows Even Viewer:
Faulting application name: MyApplication.exe, version: 1.0.0.0, time stamp: 0x601818b0
Faulting module name: PDFXEditCore.x86.dll, version: 9.0.351.0, time stamp: 0x600a19e7
Exception code: 0xc000041d
Fault offset: 0x0000000000021908
...
This happens with x86 version. For x64 I need to do more tests.

I cannot give you the exact code or steps to reproduce - as I said my code is complex. Even worst, 1 out of 3 times everything works ok, but 2 out of 3 this problem happens (this is why I need to do more tests with x64 - to make sure the problem happens there also).

What I know for sure when this happens:

1. Run some code utilizing custom IOperation and AsyncDo (including all that comes with it like ThreadSafeCall and using ProgressMon, etc). The code, in short, opens hundreds of PDF files (each in its own thread), does some stuff on PXCDocument level, saves the file. So, this is a complex memory usage scenario.
2. When the above is finished, upon trying to create a form hosting PXVControl
3. My app vanishes.
4. If I run my app under debug mode, sometimes I see C0000005 exception - but not usable - to try to figure out where exactly.

I would be happy to provide more details - as at the moment I am not able to work with 9.351 and need to go back to 8.343.

-žarko
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Support,

Here's some further investigation: I've re-checked with the x64 sdk.dll version - and the problem also happens.

Looking for more info in Event Viewer reveals that for both x86 and x64, when the app crashes, there are two "error" entries. The first one has "Exception code: 0x80000003" and the second one (immediately after the first one) is always: "0xc000041d".

I'm hoping the above will hep you narrow down the cause of this.

-žarko
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Support,

A bit more info...

I have narrowed it down to what could be causing this and, for the moment, it seems IPXC_Document::WriteToFile could be the origin of the issue.

So, again, to provide more info: I have my custom implementation of IOperation, let's call it MyOperation. The MyOperation's Do method opens a pdf file via IPXC_Inst::OpenDocumentFromFile (null for IPXC_DocAuthCallback, null for IProgressMon, 0 for the rest params), and then just saves it (so no changes to the actual file) using the same name via WriteToFile(null for progress, 0 for flags) .

Each of MyOperation instance opens a different file and saves.

This process is done via IPXV_Inst::AsyncDo.

If I skip (comment) the saving part - no issues at all.

So, my guess is that something goes wrong with memory management inside WriteToFile.

Again, the app crashes when the above process finishes for all files and I try to create a new instance of PXVControl (different form in my application)

p.s.
To repeat:, in 8.343 all the above works without any issues.

-žarko
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Support,

Here's some more info:

I'm using IPXV_Inst.Init() when my app starts - so any instances of PXVControl already have an initialized IPXV_Inst.

The app crashes when the following steps happen:

1. IPXV_Inst.Init
2. AsyncDo(MyOperation), where myOperation.Do does:
21. OpenDocumentFromFile
22. WriteToFile
... (wait for all to finish)
3. (Try to) create an instance of PXVControl -> AV here and app crashes

If I comment the 22 (saving part) -> *no* crash in 3.

Further, If I instantiate at least one PXVControl before (2), that is, the following steps:

1. IPXV_Inst.Init
2. -> Create one PXVControl <-
3. AsyncDo(MyOperation), where myOperation.Do does:
31. OpenDocumentFromFile
32. WriteToFile
4. Create another instance of PXVControl -> *all ok*

Even if I close the instance created in 2, immediately after creating it, then move to 3... -> *all ok* in 4.

p.s.
Again, all works without issues in 8.343.


I will dig more - but it would be helpful to receive some feedback at this point. Do you have any idea what's happening?

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

It's not a simple matter. Thanks for the investigation, I'm sure that it will help with finding out what the problem is.
Also, it would be great if you can answer these questions - they will be of help:
1) Are you using the EOCR plugin (somehow)?
2) Many of the interfaces were changed in the V9. If you are using some kind of wrappers, probably you have missed one or two.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Alex,

1. No.
2. Yes, using lots of wrappers, but:
2.1 The only one I had to update is IPXV_InfoBarCallbacks vs IPXV_DocInfoBarCallbacks - and no problems here...
2.2 Had to implement 4 new methods in IPXV_View - in my custom Panes - but those 4 are not even used (discussed in anther topic).

Note that, from what I can se, using WriteToFile is causing (or is somehow involved in) this ...

-žarko
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Alex,

Btw, now once I know how to recreate this - crashing happens 1/1 time (so not random).

Here's some more info...

If I execute my IOperation in the main thread, via Do() -> no issues.

If I execute via AsyncDo or AsyncDoAndWaitForFinish -> crash (as explained).

Again, in both cases, if I omit the saving part -> all ok.

So, WriteToFile from a different thread - somehow causing or involved in this.

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

Thanks for detailed investigation. Forwarded this to the developer who can probably tell more on this matter.
By the way, is it by any chance possible to create a small working project to recreate this behavior?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Alex,

I went to deep debug the code, and found that the AV happens when my framework (Delphi [Seattle], VCL, x64) calls for "IOleObject.DoVerb(OLEIVERB_INPLACEACTIVATE, ...)" as a part of the CreateWnd procedure.

Does that ring any bell?

Again: this happens only when the PXVControl is to be created/displayed *after* using various IPXV_Inst methods (and the mentioned WriteToFile).


p.s.
Creating a small project ... will try but will take time .... as it will be hard to recreate the exact "setup" in a small app - my classes implementing PDFX various interfaces and stuff are in total ~11000 lines of code...

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

Well let's hope that this info is enough for the problem investigation.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

Hi Support,

Well .. creating a sample application was more easy than I thought.

Here's small app in Delphi to show this problem:
pdfx9.351.zip
(54.22 KiB) Downloaded 62 times
image.png
image.png (10.84 KiB) Viewed 2249 times
If you run the Async call and then try to show the child form -> AV.

Any other combination -> no AV.



-žarko
User avatar
Roman - Tracker Supp
Site Admin
Posts: 303
Joined: Sun Nov 21, 2004 3:19 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by Roman - Tracker Supp »

Hi Žarko,
Thanks for the repro app. The issue has been fixed. The fix will be available in the upcoming build 352 of the Editor.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"  SOLVED

Post by zarkogajic »

Hi Alex,

Already ":("

You could have take at least a few days to fix - like it took me a week to get to the bottom of it :)

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
User avatar
Roman - Tracker Supp
Site Admin
Posts: 303
Joined: Sun Nov 21, 2004 3:19 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by Roman - Tracker Supp »

zarkogajic wrote: Fri Feb 05, 2021 9:23 am You could have take at least a few days to fix - like it took me a week to get to the bottom of it :)
Actually it is for your efforts that we managed to fix this quickly. Thanks and respect Žarko!
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by zarkogajic »

:)

p.s.
It actually had nothing to do with memory management, correct?

-žarko
User avatar
Roman - Tracker Supp
Site Admin
Posts: 303
Joined: Sun Nov 21, 2004 3:19 pm

Re: v9.351: serious memory corruption issue - app crashes with "faulting module sdk.dll"

Post by Roman - Tracker Supp »

zarkogajic wrote: Mon Feb 08, 2021 9:12 am It actually had nothing to do with memory management, correct?
Correct.
It was because one of the Editor components entered an unexpected and unrecoverable state and reported a catastrophic failure.
Post Reply