File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,23 @@ extern "C" {
11
11
12
12
using namespace cv ;
13
13
14
+ // Fix for https://github.com/sparkfun/micropython-opencv/issues/13
15
+ //
16
+ // TLDR; The CoreTLSData object gets allocated once, whenever the first OpenCV
17
+ // function that needs it happens to be called. That will only happen from the
18
+ // user's code, after the GC has been initialized, meaning it gets allocated on
19
+ // the GC heap (see `__wrap_malloc()`). If a soft reset occurs, the GC gets
20
+ // reset and overwrites the memory location, but the same memory location is
21
+ // still referenced for the CoreTLSData object, resulting in bogus values and
22
+ // subsequent `CV_Assert()` calls fail
23
+ //
24
+ // The solution here is to create a global variable that subsequently calls
25
+ // `getCoreTlsData()` to allocate the CoreTLSData object before the GC has
26
+ // been initialized, so it gets allocated on the C heap and persists through
27
+ // soft resets. `getCoreTlsData()` is not publicly exposed, but `theRNG()` is
28
+ // exposed, which just runs `return getCoreTlsData().rng`
29
+ volatile RNG rng = theRNG();
30
+
14
31
mp_obj_t cv2_core_convertScaleAbs (size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
15
32
// Define the arguments
16
33
enum { ARG_src, ARG_dst, ARG_alpha, ARG_beta };
You can’t perform that action at this time.
0 commit comments