I have a documentwindow subclass which is working fine with other simple application and working fine on windows application very well, but on mac when mouse event occurs it crashes. In juce_component class it is crashing at.
const Component* const topLevelComp = target->getTopLevelComponent();
ComponentPeer* peer = topLevelComp->getPeer();
p = peer->globalToLocal (p);
p = convertFromParentSpace (*topLevelComp, p);
if (topLevelComp == target)
where it is not getting its component peer.
Please guide me what am i doing wrong, what changes should be done on mac build since it is working on windows.
That doesn’t look like the code I have here - if you’re not running the latest version, please try that first, in case something has been fixed recently…
Thanx for your response, I am using juce 1.53, the code i have posted here is from juce_component class, where on mouse over it tries to find the component below the mouse and there it tries to find the peer of the window, and the issue follows it is not able to find the peer for the toplevelComponent.
I am attaching snapshot for you to check out.
I wanted to ask, is it possible that a documentWindow being added to the desktop might not have the peer component? If yes, what might be the issue?
That code only calls getPeer() if the component’s isOnDesktop() returns true, which should always be completely safe - it should be impossible for a component to think it’s on the desktop without also having a peer.
You say you’re using a DocumentWindow subclass, so perhaps you’ve overridden one of its methods in a way that prevents the parent class from functioning correctly?
Instead of using my subclass of DocumentWindow I tried with DocumentWindow class object itself, i was trying to run that window as modal, and it has the same issue.
AFAICT it should be impossible for that code to go wrong. Can you post some example code that I could run to reproduce the problem?
I am still trying to figure out that crash. After doing lots of debugging I found that below function is defined in juce_win32_Windowing.cpp and it is not there in Component.cpp. And i found that it is defined as pure virtual.
const Point localToGlobal (const Point& relativePosition)
return relativePosition + getScreenPosition();
const Point<int> globalToLocal (const Point<int>& screenPosition)
return screenPosition - getScreenPosition();
And I found the same functions are overridden in NSViewComponentPeer as well, but when it is called on mac it seems it is not calling the NSViewComponentPeer function.
I am totally confused, please help me
Please take a look on the screenshot, after doing setVisible it has the following call stack, though it should go to the drawRect method of the window. Please guide me what might be the reason of such crash.
Your stack is corrupted there - the last couple of entries don’t make any sense, isOpaque doesn’t contain any calls to sendDragCallback. Looks to me like you’ve got a dangling pointer or something.
This is the complete call stack, thought it is same till makeKeyAndOrderFront for other applications also but in my project it is jumping to crash. I dont understand where the dangling pointer would come into the picture.
Like I already said: isOpaque does not call sendDragCallback, so that stack is obviously corrupted - posting it again won’t make it any more useful than last time (!)
The reason I said that a component is probably a dangling pointer is because when isOpaque gets called, it could be hitting some junk pointers and calling off to some other random place in the code. You need to debug your app and find out what’s going wrong before this point, because by the time your stack is corrupted, it’s too late to work out why.