Cocoa backend: added checks before accessing sliders dictionary
This commit is contained in:
parent
177aef05b6
commit
ee2f8d006f
@ -230,9 +230,11 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr)
|
||||
//Set new view size considering sliders (reserve height and min width)
|
||||
NSRect vrectNew = vrectOld;
|
||||
int slider_height = 0;
|
||||
if ([window respondsToSelector:@selector(sliders)]) {
|
||||
for(NSString *key in [window sliders]) {
|
||||
slider_height += [[[window sliders] valueForKey:key] frame].size.height;
|
||||
}
|
||||
}
|
||||
vrectNew.size.height = [[[window contentView] image] size].height + slider_height;
|
||||
vrectNew.size.width = std::max<int>([[[window contentView] image] size].width, MIN_SLIDER_WIDTH);
|
||||
[[window contentView] setFrameSize:vrectNew.size]; //adjust sliders to fit new window size
|
||||
@ -331,10 +333,13 @@ CV_IMPL int cvCreateTrackbar2(const char* trackbar_name,
|
||||
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
|
||||
int res = cvCreateTrackbar(trackbar_name, window_name, val, count, NULL);
|
||||
if(res) {
|
||||
CVSlider *slider = [[cvGetWindow(window_name) sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
||||
CVWindow *window = cvGetWindow(window_name);
|
||||
if (window && [window respondsToSelector:@selector(sliders)]) {
|
||||
CVSlider *slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
||||
[slider setCallback2:on_notify2];
|
||||
[slider setUserData:userdata];
|
||||
}
|
||||
}
|
||||
[localpool drain];
|
||||
return res;
|
||||
}
|
||||
@ -383,7 +388,7 @@ cvSetMouseCallback( const char* name, CvMouseCallback function, void* info)
|
||||
localpool4 = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
window = cvGetWindow(window_name);
|
||||
if(window) {
|
||||
if(window && [window respondsToSelector:@selector(sliders)]) {
|
||||
CVSlider *slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
||||
if(slider) {
|
||||
pos = [[slider slider] intValue];
|
||||
@ -414,7 +419,7 @@ CV_IMPL void cvSetTrackbarPos(const char* trackbar_name, const char* window_name
|
||||
localpool5 = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
window = cvGetWindow(window_name);
|
||||
if(window) {
|
||||
if(window && [window respondsToSelector:@selector(sliders)]) {
|
||||
slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
||||
if(slider) {
|
||||
[[slider slider] setIntValue:pos];
|
||||
@ -442,7 +447,7 @@ CV_IMPL void cvSetTrackbarMax(const char* trackbar_name, const char* window_name
|
||||
localpool5 = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
window = cvGetWindow(window_name);
|
||||
if(window) {
|
||||
if(window && [window respondsToSelector:@selector(sliders)]) {
|
||||
slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
||||
if(slider) {
|
||||
if(maxval >= 0) {
|
||||
@ -473,7 +478,7 @@ CV_IMPL void cvSetTrackbarMin(const char* trackbar_name, const char* window_name
|
||||
localpool5 = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
window = cvGetWindow(window_name);
|
||||
if(window) {
|
||||
if(window && [window respondsToSelector:@selector(sliders)]) {
|
||||
slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]];
|
||||
if(slider) {
|
||||
if(minval >= 0) {
|
||||
@ -709,10 +714,12 @@ void cv::setWindowTitle(const String& winname, const String& title)
|
||||
double viewHeight = [self contentView].frame.size.height;
|
||||
double viewWidth = [self contentView].frame.size.width;
|
||||
CVWindow *window = (CVWindow *)[[self contentView] window];
|
||||
if ([window respondsToSelector:@selector(sliders)]) {
|
||||
for(NSString *key in [window sliders]) {
|
||||
NSSlider *slider = [[window sliders] valueForKey:key];
|
||||
viewHeight = std::min(viewHeight, (double)([slider frame].origin.y));
|
||||
}
|
||||
}
|
||||
viewHeight -= TOP_BORDER;
|
||||
mp.y = viewHeight - mp.y;
|
||||
|
||||
@ -929,6 +936,7 @@ void cv::setWindowTitle(const String& winname, const String& title)
|
||||
int height = size.height;
|
||||
|
||||
CVWindow *cvwindow = (CVWindow *)[self window];
|
||||
if ([cvwindow respondsToSelector:@selector(sliders)]) {
|
||||
for(NSString *key in [cvwindow sliders]) {
|
||||
NSSlider *slider = [[cvwindow sliders] valueForKey:key];
|
||||
NSRect r = [slider frame];
|
||||
@ -937,6 +945,7 @@ void cv::setWindowTitle(const String& winname, const String& title)
|
||||
[slider setFrame:r];
|
||||
height -= r.size.height;
|
||||
}
|
||||
}
|
||||
[localpool drain];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user