PLO. Application issues - page 14

 
Yedelkin:

"Invalid pointer access" =="Attempting to access an invalid pointer"? If yes, then

A pointer may be invalid in the following cases:

  • the pointer is NULL;
  • if the object was deleted using the delete operator.

The first case is mine.

I would be glad to use CheckPointer() and other check methods (I was born not in the morning), but tearing down EA from chart doesn't give me a chance.

Let me get it straight - if I specify in constructor that pointer is equal to NULL and stop any actions with it, Expert Advisor will get 281 and will exit (while according to my idea it shouldn't).

But if you call Init or InitXXX after constructor (similar to CExpert) , everything works properly...

 
Interesting:

The first option is my case.

I would be glad to use CheckPointer() and other check methods (I was born on the same day), but crashing EA from the chart doesn't give me a chance to do it.

Let me get it straight - if I specify in constructor that pointer is equal to NULL and break all possible actions with it, EA will get 281 and will exit (and according to my idea it shouldn't).

But if you call Init or InitXXX after constructor (similar to CExpert) , everything works properly...


If you had handled exceptions you could easily figure out what the issue was and work it out.
 
Interesting:

The first option is my case.

I would be glad to use CheckPointer() and other check methods (I think I was born not yesterday), but tearing down EA from chart doesn't give me a chance to do it.

Let me get it straight - if I specify in constructor that pointer is equal to NULL and stop any actions with it, Expert Advisor will get 281 and will exit (while according to my idea it shouldn't).

If you call Init or InitXXX after the constructor (similar to CExpert) , everything works as it should...

I have not dealt with Init or InitXXX methods yet, but I would interpret "EA crashing" in itself as follows: the program at runtime bumps into incorrect pointer and this bottleneck must be searched in the code. My constructor initializes a pointer to NULL too, but nothing flies out.

If I have understood the question wrong, sorry.

 
Interesting:

Thank you, now everything is in its place. But, there is an additional question - Suppose error 281 occurs, but it is desirable that the EA is not unloaded. How should we handle it?

Let me clarify my question: What to do if error 281 occurs after all steps of the initialization, but it won't affect the main work of the Expert Advisor critically enough not to run it at all?

There will be no exception handling.

There is only one way out - do not use incorrect pointers.

If there is a possibility (other than zero) that a pointer may be incorrect, be sure to check it before using it.

 
uncleVic:

There will be no exception handling.

The only way out is not to use invalid pointers.

If there is a possibility (other than zero) that a pointer could be incorrect, be sure to test it before using it.


The possibility (other than zero) that a pointer could be invalid is ALWAYS probable!

Therefore you must always check its validity before EVERY use! Not just after creation.

Not always, but that's what I do at critical points :(


Oh shit, what a pure transparent code turns into :) when using your recommendation.

 
Yedelkin:

I haven't dealt with Init or InitXXX methods yet, but I would interpret "taking EA off the chart" in itself as follows: the program during its execution bumps into incorrect pointer and we have to look for this very bottleneck in the code. My constructor initializes a pointer to NULL too, but nothing flies out.

If I misunderstood the question, I'm sorry.

If you are talking about CExpert class, you must call at least Init(...). All pointers there are initialized as pointers to objects of base classes...
 
falkov:

The possibility (other than zero) that a pointer could be invalid is ABSOLUTELY ALWAYS possible!

So you should always check its validity before EVERY use!

Not always, but in critical areas I do :(


Holy shit, what a pure transparent code turns into :) when using your recommendation.

Alternative: Have clean transparent code that flies off on Invalid pointer?
 
uncleVic:
Alternative: Have a clean, transparent code that flies out on Invalid pointer?

Alternative: Have clean, transparent code.

On Invalid pointer and other exceptional situations (power failure, disk space, etc. EXCLUSIVE situations) the program goes to the exception handling block, where the respected Interesting (and me too :) could print variable values and error, analyze the situation and understand what the problem is. And, if there is no reaction to what happened in this block, drop out.

Of course, this does not invalidate the standard and necessary checks. This is ONLY applicable in EXCEPTIONAL SITUATIONS.

 
uncleVic:
If it is CExpert class, you must call at least Init(...). All pointers there are initialized as pointers to objects of base classes...

For example, if Init or InitXXX is executed with an error (returns false), what then?

Or what to do if at the time of execution the EA still receives 281 (despite all checks and tricks), but there is no trader around?

It's not a good idea:

If you had handled exceptions, you could easily figure out what was wrong and handle the situation.

The checks are there almost every step, but unfortunately the processing is not there...

PS

So, about EA dropping out of chart - what to do to make EA "alive" in any initialization?

 
uncleVic:
Alternative: To have clean transparent code, crashing by Invalid pointer?

Well, that's the point that it flies out, let "me" myself to decide in this case whether the expert should be pulled down or not.

After all, we're not even talking about "broken" pointer being applied somewhere, although I personally have a check before applying it (although I can implement another check in the timer).

I've somehow learned to live in harmony with indicators and I don't care much about results of initialization, but I can't make friends with pointers.

Yedelkin:

I haven't dealt with Init or InitXXX methods yet, but I would interpret "EA dumping" as follows: the program at runtime bumps into an incorrect pointer and this bottleneck must be searched in the code. My constructor initializes a pointer to NULL too, but nothing flies out.

If I have misunderstood the question, I apologize.

Currently, in order to solve the problem I'm returning 0 in the initialization block.

int OnInit()
{
//----------------------------------------------------------------------------//

//Processing process of the initialization

//----------------------------------------------------------------------------//
return(0);
//----------------------------------------------------------------------------//
}

As I understood it's the best way out for me (so EA won't crash on initialization). I.e. in any case result OnInit = 0, I can't judge how correct it is.