-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1728 from shimat/fix_code_warnings
Fix code issues by ReSharper
- Loading branch information
Showing
192 changed files
with
731 additions
and
1,614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,79 @@ | ||
#if DOTNETCORE | ||
using System; | ||
using System.Threading; | ||
|
||
namespace OpenCvSharp.Internal | ||
namespace OpenCvSharp.Internal; | ||
|
||
/// <summary> | ||
/// This static class defines one instance which than can be used by multiple threads to gather exception information from OpenCV | ||
/// Implemented as a singleton | ||
/// </summary> | ||
public static class ExceptionHandler | ||
{ | ||
// ThreadLocal variables to save the exception for the current thread | ||
private static readonly ThreadLocal<bool> exceptionHappened = new(false); | ||
private static readonly ThreadLocal<ErrorCode> localStatus = new(); | ||
private static readonly ThreadLocal<string> localFuncName = new(); | ||
private static readonly ThreadLocal<string> localErrMsg = new(); | ||
private static readonly ThreadLocal<string> localFileName = new(); | ||
private static readonly ThreadLocal<int> localLine = new(); | ||
|
||
/// <summary> | ||
/// This static class defines one instance which than can be used by multiple threads to gather exception information from OpenCV | ||
/// Implemented as a singleton | ||
/// Callback function invoked by OpenCV when exception occurs | ||
/// Stores the information locally for every thread | ||
/// </summary> | ||
public static class ExceptionHandler | ||
{ | ||
// ThreadLocal variables to save the exception for the current thread | ||
private static readonly ThreadLocal<bool> exceptionHappened = new ThreadLocal<bool>(false); | ||
private static readonly ThreadLocal<ErrorCode> localStatus = new ThreadLocal<ErrorCode>(); | ||
private static readonly ThreadLocal<string> localFuncName = new ThreadLocal<string>(); | ||
private static readonly ThreadLocal<string> localErrMsg = new ThreadLocal<string>(); | ||
private static readonly ThreadLocal<string> localFileName = new ThreadLocal<string>(); | ||
private static readonly ThreadLocal<int> localLine = new ThreadLocal<int>(); | ||
|
||
/// <summary> | ||
/// Callback function invoked by OpenCV when exception occurs | ||
/// Stores the information locally for every thread | ||
/// </summary> | ||
public static readonly CvErrorCallback ErrorHandlerCallback = | ||
delegate (ErrorCode status, string funcName, string errMsg, string fileName, int line, IntPtr userData) | ||
{ | ||
try | ||
{ | ||
return 0; | ||
} | ||
finally | ||
{ | ||
exceptionHappened.Value = true; | ||
localStatus.Value = status; | ||
localErrMsg.Value = errMsg; | ||
localFileName.Value = fileName; | ||
localLine.Value = line; | ||
localFuncName.Value = funcName; | ||
} | ||
}; | ||
|
||
/// <summary> | ||
/// Registers the callback function to OpenCV, so exception caught before the p/invoke boundary | ||
/// </summary> | ||
public static void RegisterExceptionCallback() | ||
public static readonly CvErrorCallback ErrorHandlerCallback = | ||
delegate (ErrorCode status, string funcName, string errMsg, string fileName, int line, IntPtr userData) | ||
{ | ||
IntPtr zero = IntPtr.Zero; | ||
IntPtr ret = NativeMethods.redirectError(ErrorHandlerCallback, zero, ref zero); | ||
} | ||
|
||
/// <summary> | ||
/// Throws appropriate exception if one happened | ||
/// </summary> | ||
public static void ThrowPossibleException() | ||
{ | ||
if (CheckForException()) | ||
try | ||
{ | ||
throw new OpenCVException( | ||
localStatus.Value, | ||
localFuncName.Value ?? "", | ||
localErrMsg.Value ?? "", | ||
localFileName.Value ?? "", | ||
localLine.Value); | ||
return 0; | ||
} | ||
} | ||
finally | ||
{ | ||
exceptionHappened.Value = true; | ||
localStatus.Value = status; | ||
localErrMsg.Value = errMsg; | ||
localFileName.Value = fileName; | ||
localLine.Value = line; | ||
localFuncName.Value = funcName; | ||
} | ||
}; | ||
|
||
/// <summary> | ||
/// Returns a boolean which indicates if an exception occured for the current thread | ||
/// Reading this value changes its state, so an exception is handled only once | ||
/// </summary> | ||
private static bool CheckForException() | ||
/// <summary> | ||
/// Registers the callback function to OpenCV, so exception caught before the p/invoke boundary | ||
/// </summary> | ||
public static void RegisterExceptionCallback() | ||
{ | ||
IntPtr zero = IntPtr.Zero; | ||
IntPtr ret = NativeMethods.redirectError(ErrorHandlerCallback, zero, ref zero); | ||
} | ||
|
||
/// <summary> | ||
/// Throws appropriate exception if one happened | ||
/// </summary> | ||
public static void ThrowPossibleException() | ||
{ | ||
if (CheckForException()) | ||
{ | ||
var value = exceptionHappened.Value; | ||
// reset exception value | ||
exceptionHappened.Value = false; | ||
return value; | ||
throw new OpenCVException( | ||
localStatus.Value, | ||
localFuncName.Value ?? "", | ||
localErrMsg.Value ?? "", | ||
localFileName.Value ?? "", | ||
localLine.Value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns a boolean which indicates if an exception occured for the current thread | ||
/// Reading this value changes its state, so an exception is handled only once | ||
/// </summary> | ||
private static bool CheckForException() | ||
{ | ||
var value = exceptionHappened.Value; | ||
// reset exception value | ||
exceptionHappened.Value = false; | ||
return value; | ||
} | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.