Warning Message for "Self" in AVCaptureMetadataOutputObjectsDelegate - angle

I am getting the following warning, and I am not sure how to fix it or if it is serious:
This is for the self statement that is enclosed in asterisks: sending ViewController warning message "const__strong to parameter of incompatible type AVCaptureMetadataOutputObjectsDelegate
- (void) setupAVFoundationFaceDetection
{
self.metadataOutput = [AVCaptureMetadataOutput new];
if (! [self.session canAddOutput:self.metadataOutput])
{
NSLog (#"\nCould not add Face Detection...\n");
return;
}
NSLog (#"\nIn Face Detection...\n");
[self.metadataOutput setMetadataObjectsDelegate:**self** queue:dispatch_get_main_queue()];
[self.session addOutput:self.metadataOutput];
if (! [self.metadataOutput.availableMetadataObjectTypes containsObject:AVMetadataObjectTypeFace] )
{
NSLog(#"Face Detection is not supported\n");
// [self teardownAVFFoundationFaceDetection];
return;
}
self.metadataOutput.metadataObjectTypes = #[AVMetadataObjectTypeFace];
}

[self.metadataOutput setMetadataObjectsDelegate:(id)self queue:dispatch_get_main_queue()];
somewhat late but might be helpful to people searching for the answer :)

Related

Get abending line number in C++ using Visual Studio

Okay, I've been beating my head against a brick wall for a couple of days now...
I have a __try __except piece of code with this in it:
__except(ExFilter(GetExceptionCode(),GetExceptionInformation())){
// Print the message ExFilter set up
MessageBox(NULL, (LPTSTR)outline, "setup/LoadSettingsFromIni error", MB_OK);
if(ExFilter_rc > 0) { // should we abend?
exit(9) ; // yes
}
} // end of __except...
and in the ExFilter code:
LONG ExFilter(DWORD error,LPEXCEPTION_POINTERS lpExceptionInfo){
void *addressPtr;
EXCEPTION_RECORD *myExecptionRecord;
myExecptionRecord = lpExceptionInfo->ExceptionRecord;
addressPtr = myExecptionRecord->ExceptionAddress;
At this point, addressPtr points to:
0x00007ff73b70d4c8 {Regshot-x64-ANSI-dbg.exe!LoadSettingsFromIni(HWND__ * hDlg), Line 355}
More of the code gets the program name using "GetModuleFileName" etc.
But I already know the program name.
I've tried many ways to get the data "Line 355" but no luck.
How do I get at it so I can put it in a message?
Thanks.
I'm sure many people have found a way around this, but here is my "poor man's solution" for trapping errors I suddenly thought of the other day:
I added a counter to areas in my code that might cause a problem, and then in the __except filter added code to show the counter, which would give me a more concise area to look at.
Here is what I did:
char outline[1310] ; // __except output line
size_t rc2 ; // lth of outline
int ctr ;
__try {
code
..
ctr = 1 ;
code
..
ctr = 2 ;
code
..
ctr = 3 ;
code
..
} // end of try
__except(ExFilter(GetExceptionCode(),GetExceptionInformation())){
// Print the message ExFilter set up
MessageBox(NULL, (LPTSTR)outline, "setup/LoadSettingsFromIni error", MB_OK);
if(ExFilter_rc > 0) { // should we abend?
exit(9) ; // yes
}
} // end of __except...
and in the ExFilter code:
LONG ExFilter(DWORD error,LPEXCEPTION_POINTERS
lpExceptionInfo){
void *addressPtr;
EXCEPTION_RECORD *myExecptionRecord;
myExecptionRecord = lpExceptionInfo->ExceptionRecord;
addressPtr = myExecptionRecord->ExceptionAddress;
sprintf(outline, ""); // blank outline
rc2 = strlen(outline);
rc = error ; // GetExceptionCode() passed by __except
if (rc == EXCEPTION_INT_DIVIDE_BY_ZERO) {
sprintf(outline+rc2, "Divide by Zero!");
goto f_end7a ; // continue
}
... more code for each trapped error.....
f_end7a: ;
rc2 = strlen(outline);
sprintf(outline+rc2, "\n\nError occured after instruction \"ctr = %i ;\" \n", ctr);
return EXCEPTION_EXECUTE_HANDLER; // return to __except...
So if an error occurs, a message is displayed, with a line like:
Error occurred after instruction "ctr = 2"
and I know approximately where it happened, between ctr = 2 and ctr = 3.
This may be "Mickey Mouse", but it's better than nothing.

Getting Unchecked return value from library?

Calling remove(file.txt) without checking return value. This library function may fail and return an error code
I am getting above warning in below code-
bool chkfile() {
std::remove(file.txt);
return true;
}
How should I remove this warning?
You can refer to this link to see the issue. You have to check if there is no issue during remove operation.
Your code should be something like this,
bool chkfile() {
if (std::remove("file.txt") != 0) {
// error handling
} else {
// success
return true;
}
}

result of call warning - want to use the result?

I have some difficulties with the new Swift 3.0. First I know the “result of call is unused” warning has been debated a few times already. I have read the topics in question and usually the suggested answer is to use #discardableResult or using _ = before the function. But in my case this isn’t working. Before upgrading xCode the code worked great. I tested it on my iPad and everything was ok. But then once I upgraded xCode and had to convert the code to comply with Swift 3.0 the problem appeared.
The thing is that whatever I do, the object in the game isn’t showing as it should. Like I said, previously it worked, but now it doesn’t anymore. When the character runs into the object and it crashes it, the game should display a crashed object, but instead it shows an image with a red “X” as if the image isn’t there.
Here is the code. I would appreciate any suggestion you guys have. Thanks in advance
for block in Blocks
{
block.move()
block.isColB()
if(block.manager.HasFloorL2)
{
if(block.isOnL2())
{
if(block.manager.FloorL2Obstact)
{
block.ObsColL2() // here, result of call to ObscColL2() is unused
}
break;
}
}
if(block.manager.HasFloorL1)
{
if(block.isOnL1())
{
if(block.manager.FloorL1Obstact)
{
block.ObsColL1() // here, result of call to ObscColL1() is unused
}
break;
}
}
}
Here is the function it refers to.
func ObsColL1() -> Bool
{
if(kong.Node.position.x+kong.Node.size.width*0.7 > self.holder.position.x+ObstacleL1.Node.position.x
&& kong.Node.position.x+kong.Node.size.width*0.7 < self.holder.position.x+ObstacleL1.Node.position.x+ObstacleL1.Node.size.width*0.3)
{
if(kong.Y() <= self.holder.position.y+(ObstacleL1.Node.position.y)+ObstacleL1.Node.size.height*0.7 && kong.Y() >= self.holder.position.y+ObstacleL1.Node.position.y)
{
if(kong.state != heroStates.flash && !self.ObstacleL1.crashed)
{
kong.Node.position.x = self.holder.position.x+ObstacleL1.Node.position.x-(kong.Node.size.width*0.55)
kong.Node.run(SKAction.moveTo(y: self.holder.position.y+ObstacleL1.Node.position.y+ObstacleL1.Node.size.height/2, duration: 0.5))
kong.die()
}
else
{
ObstacleL1.crash()
return true
}
}
}
return false
}
EDIT:
before and after
before and after
before and after 2

Check user input for errors elegantly

My program waits for user input, and when appropriate, will process it. I need to check the user input to make sure it fulfils certain criteria, and if it doesn't fulfil all of those criteria it will be rejected.
Pseudo-code is something like:
if (fulfills_condition_1)
{
if (fulfills_condition_2)
{
if (fulfills_condition_3)
{
/*process message*/
}
else
cout << error_message_3; //where error_message_1 is a string detailing error
}
else
cout << error_message_2; //where error_message_2 is a string detailing error
}
else
cout << error_message_1; //where error_message_3 is a string detailing error
There is the possibility that the number of these conditions could increase, and I was wondering if there was a neater way to represent this using a switch or something like that instead of lots of cascading if statements.
I know there is the possibility of using
if (fulfills_condition_1 && fulfills_condition_2 && fulfills_condition_3)
/*process message*/
else
error_message; //"this message is not formatted properly"
but this is less useful than the first, and does not say where the issue is.
The conditions can roughly be arranged in increasing importance i.e. checking for condition_1 is more important than checking for condition_3, so the if statements do work - but is there a better way in general for doing this?
How about
if (!fulfills_condition_1) throw BadInput(error_message_1);
if (!fulfills_condition_2) throw BadInput(error_message_2);
if (!fulfills_condition_3) throw BadInput(error_message_3);
/* process message */
Then your exception handler can report the error message, and retry or abort as appropriate.
If what bothers you are the cascading ifs, you could go for one of the following:
Using a boolean:
bool is_valid = true;
string error = "";
if (!condition_one) {
error = "my error";
is_valid = false;
}
if (is_valid && !condition_two) {
...
}
...
if (!is_valid) {
cout << error;
} else {
// Do something with valid input
}
Using exceptions:
try {
if (!condition_one) {
throw runtime_error("my error");
}
if (!condition_two) {
...
}
...
} catch (...) {
// Handle your exception here
}
I suggest you can use "early return" technique:
if (!fulfills_condition_1)
// error msg here.
return;
// fulfills_condition1 holds here.
if (!fulfills_condition_2)
// error msg here.
return;
// Both conditon1 and condition2 hold here.
if (!fulfills_condition_3)
// error msg here.
return.
If this was going to be reused in a few places, I would make a DSL:
Validator inputType1Validator =
Validator.should(fulfill_condition_1, error_message_1)
.and(fulfill_condition_2, error_message_2)
.and(fulfill_condition_3, error_message_3)
inputType1Validator.check(input);

How are error-handling statements formatted?

I have a few functions that return a 1 if an error is encountered. Each function calls on a lower-level function, such that if the lower-level function returns a 1, the original function returns a 1 as well. Thus errors get passed up the chain in this way.
Here's an highly abridged version of one of these functions:
if (low_level_function()) {
[do stuff]
return 1;
}
[do other stuff]
return 0;
Should I instead declare an error variable, assign the result of low_level_function() to it, and then use the error variable in the if() statement? In other words:
int error = low_level_function();
if (error) {
[do stuff]
return 1;
}
[do other stuff]
return 0;
Or is there yet another, better way of doing this? I've never coded to account for errors before, so my experience here is rather limited.
Edit: I've reformatted the functions to better convey the nature of my code.
One reason to prefer the second form is when you don't have anything to do in the error case and you want to avoid the stair-step effect of nested if statements.
int error_flag = low_level_function();
if (!error_flag)
error_flag = second_function();
if (!error_flag)
error_flag = third_function();
return error_flag;
Of course for that specific example you can really simplify by using the short-circuiting property of ||:
return low_level_function() || second_function() || third_function();
I dont see the difference between the two approaches above.
I would recomment using exception, much more cleaner approach. why the reinvent the wheel? You can either use standard exception or implement custome exception like
You can use this also,
return low_level_function();
If low_level_function() returns nonzero on error and zero on success. Or
return low_level_function()>0? 1 : 0;
Although it it's s side comment I´ll be first stateing that I prefer one exit for any method.
One major pro tof his construction is the possiblity to only have the need for a error-logging statement at one place.
Also it's very easy to add tracing logs for debugging porpose.
So following this idea I'd propose the following
#define OK (0)
int mid_level_func(....)
{
log_entry(...);
int rc = OK
{
...
if ((rc = low_level_func1(...)))
goto lblExit;
...
if ((rc = low_level_func2(...)))
goto lblExit;
...
lblExit:
;
}
if (OK != rc)
log_error(rc, ...);
log_exit(...);
return rc;
}
For the ones that insist on goto being 'evil' the following variation on the scheme above might help:
#define OK (0)
int mid_level_func(....)
{
log_entry(...);
int rc = OK
do
{
...
if ((rc = low_level_func1(...)))
break;
...
if ((rc = low_level_func2(...)))
break;
...
} while (0);
if (OK != rc)
log_error(rc, ...);
log_exit(...);
return rc;
}