Commit 4d228febb830296517f9b930194869d876ffe23f
1 parent
0de4de86
fixed pointer bug which caused the crash
Showing
2 changed files
with
13 additions
and
7 deletions
openbr/plugins/cuda/MatManager.cu
| ... | ... | @@ -15,12 +15,13 @@ namespace br { namespace cuda { |
| 15 | 15 | // initialize the an array of Mats |
| 16 | 16 | _mats = (uint8_t**)malloc(num * sizeof(uint8_t*)); |
| 17 | 17 | _matTaken = (bool**)malloc(num * sizeof(bool*)); |
| 18 | - _matsDimension = (int**) malloc(num * sizeof(int)); | |
| 18 | + _matsDimension = (int**)malloc(num * sizeof(int*)); | |
| 19 | 19 | |
| 20 | 20 | for (int i=0; i < num; i++) { |
| 21 | 21 | cudaMalloc(&_mats[i], 1 * sizeof(uint8_t)); |
| 22 | 22 | //_mats[i] = new GpuMat(); |
| 23 | 23 | |
| 24 | + // initialize matTaken | |
| 24 | 25 | _matTaken[i] = new bool; |
| 25 | 26 | (*_matTaken[i]) = false; |
| 26 | 27 | |
| ... | ... | @@ -69,14 +70,14 @@ namespace br { namespace cuda { |
| 69 | 70 | //printSizeChangingMat(reservedMat); |
| 70 | 71 | //reservedMat->release(); |
| 71 | 72 | //reservedMat->create(mat->size(), mat->type()); |
| 72 | - std::cout << "Size mismatch" << std::endl << std::flush; | |
| 73 | + std::cout << "Size mismatch" << std::endl << std::flush; | |
| 73 | 74 | // re malloc |
| 74 | 75 | cudaFree(_mats[reservedMatIndex]); // free the previous memory first |
| 75 | 76 | cudaMalloc(&_mats[reservedMatIndex], mat->rows * mat->cols * sizeof(uint8_t)); |
| 76 | 77 | // change the dimension of that matrix |
| 77 | - *_matsDimension[reservedMatIndex] = mat->rows * mat->cols; | |
| 78 | + *_matsDimension[reservedMatIndex] = mat->rows * mat->cols; | |
| 78 | 79 | |
| 79 | - } | |
| 80 | + } | |
| 80 | 81 | pthread_mutex_unlock(_matsDimensionLock); |
| 81 | 82 | return _mats[reservedMatIndex]; |
| 82 | 83 | } |
| ... | ... | @@ -99,7 +100,7 @@ namespace br { namespace cuda { |
| 99 | 100 | reservedMat->download(dstMat); |
| 100 | 101 | pthread_mutex_unlock(_matsDimensionLock); |
| 101 | 102 | */ |
| 102 | - | |
| 103 | + | |
| 103 | 104 | // copy the mat data back |
| 104 | 105 | int dimension = dstMat.rows * dstMat.cols; |
| 105 | 106 | cudaMemcpy(dstMat.ptr<uint8_t>(), reservedMat, dimension, cudaMemcpyDeviceToHost); |
| ... | ... | @@ -128,9 +129,9 @@ namespace br { namespace cuda { |
| 128 | 129 | int type = reservedMat->type(); |
| 129 | 130 | reservedMat->release(); |
| 130 | 131 | reservedMat->create(size, type); |
| 131 | - | |
| 132 | 132 | |
| 133 | - | |
| 133 | + | |
| 134 | + | |
| 134 | 135 | pthread_mutex_unlock(_matsDimensionLock); |
| 135 | 136 | */ |
| 136 | 137 | ... | ... |