Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AV error on program shutdown #456

Closed Answered by Andyk1234
Andyk1234 asked this question in Q&A
Discussion options

After running a python script, P4D causes an AV error during program shutdown in the following routine...

It seems to be referring to one of my objects as if it support interfaces, which it doesn't.

The object has not been wrapped, so there is nothing to free, it is an internal object created in my app and the properties/methods exposed using the RegisterDelphiWrapper function.

In wrapDelphi unit

procedure TPyDelphiObject.UnSubscribeToFreeNotification;
var
 _FreeNotification : IFreeNotification;
begin
 Assert(Assigned(fDelphiObject));
 if fDelphiObject.GetInterface(IFreeNotification, _FreeNotification) then //<<<< produces AV error
 _FreeNotification.UnSubscribe(Self);
end;

In my Python setup I define

 PydelphiWrapper1.RegisterDelphiWrapper(TPyClassWrapper<Ttest>).Initialize;
 //
 p := PyDelphiWrapper1.Wrap(Ttests.create, soOwned);
 PythonModule1.SetVar( 'Tests', p );
 PythonEngine1.Py_DecRef(p);

Where tests holds and maintains a list of Ttest created in the program by the user.

and the Python code...

import Spam as sp
Tsts = sp.Tests
print(Tsts.Count)
print(Tsts[0].Name)
#a = Tsts[0]
#print(a.Name)

The first print works and creates no error when the program is closed.

If I unhash the commented out line, it works the same, but the error occurs on program shutdown.

I have currently worked around this by by wrapping the P4D line that causes the error with a try/except

procedure TPyDelphiObject.UnSubscribeToFreeNotification;
var
 _FreeNotification : IFreeNotification;
begin
 Assert(Assigned(fDelphiObject));
 try
 if fDelphiObject.GetInterface(IFreeNotification, _FreeNotification) then
 _FreeNotification.UnSubscribe(Self);
 except
 end;
end;

Which allows the program to shutdown properly but a bit annoying when running under debugging.

is there a way to stop this function being called on shutdown when they shouldn't be ?

You must be logged in to vote

Hi, took me a long time to track this down, but it appears to be a problem with Synedit rather than P4D.

It was a weird one, having between 70 and 81 characters in the editor caused the problem on shutdown.

I didn't even need to run any python code and it still did it, it must be a memory corruption caused by the editor.

It seems the version of SynEdit I had dated back to 2014, I have upgraded to the latest and the problem has gone away.

Replies: 3 comments

Comment options

Could you please post a Delphi project that reproduces the error?

You must be logged in to vote
0 replies
Comment options

Hi, I'll try and create a standalone simple project that reproduces the error.

Strangely, I have found that adding more python lines of code stops the error from occurring, it only seems to happen on the first access to a delphi object and providing no other accesses are made.

You must be logged in to vote
0 replies
Comment options

Hi, took me a long time to track this down, but it appears to be a problem with Synedit rather than P4D.

It was a weird one, having between 70 and 81 characters in the editor caused the problem on shutdown.

I didn't even need to run any python code and it still did it, it must be a memory corruption caused by the editor.

It seems the version of SynEdit I had dated back to 2014, I have upgraded to the latest and the problem has gone away.

You must be logged in to vote
0 replies
Answer selected by pyscripter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /