CursorControl pointer is null CIrrDeviceMacOSX.mm

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by Donald Duck »

I compiled Irrlicht 1.8.4 on Mac and used it in one of my projects. But when I use the function irr::createDeviceEx in my code, the program crashes. This is what it gives when I run it in the terminal:

Code: Select all

Last login: Mon May 15 12:57:25 on ttys000
/Users/donaldduck/Documents/build-untitled/Mac/untitled.app/Contents/MacOS/untitled ; exit;
donalds-iMac:~ donaldduck$ /Users/donaldduck/Documents/build-untitled/Mac/untitled.app/Contents/MacOS/untitled ; exit;
Irrlicht Engine version 1.8.4
Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64
No doublebuffering available.
Segmentation fault: 11
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
 
[Process completed]
After some debugging, I found out that it was because the pointer CursorControl is null at line 1289 in CIrrDeviceMacOSX.mm. This is the line in question:

Code: Select all

const core::position2di& curr = ((CCursorControl *)CursorControl)->getPosition();
Can this bug please be fixed?
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by MartinVee »

I don't have MacOSX here, but looking at the code, I see that in the same file, around line 623, there's this line of code in the constructor :

Code: Select all

CursorControl = new CCursorControl(CreationParams.WindowSize, this);
If you put a breakpoint there, can you tell us the values of the parameters passed to the CCursorControl constructor, and if the CursorControl object is null after the call?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by CuteAlien »

CursorControl is one of the first variables accessed when calling device->run(). So maybe your device pointer itself is broken?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by Donald Duck »

MartinVee wrote:If you put a breakpoint there, can you tell us the values of the parameters passed to the CCursorControl constructor, and if the CursorControl object is null after the call?
I did that, and apparently it never runs the constructor, at least not before it crashes. It runs irr::createDeviceEx from my code and from there it runs CIrrDeviceMacOSX::run and from there it runs CIrrDeviceMacOSX::storeMouseLocation. It runs the run() method from a variable called dev which is of type irr::CIrrDeviceMacOSX*, but it uses the constructor CIrrDeviceConsole. At line 102 in Irrlicht.cpp, this is where this variable gets initialized:

Code: Select all

dev = new CIrrDeviceConsole(params);
CuteAlien wrote:CursorControl is one of the first variables accessed when calling device->run(). So maybe your device pointer itself is broken?
The part that crashes is run from irr::createDeviceEx, so that's where I'm creating my device.
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by MartinVee »

Can you post a mininimal example that reproduces the problem?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by CuteAlien »

Strange, the dev variable should be type IrrlichtDevice* and not CIrrDeviceMacOSX*. At least in my Irrlicht.cpp. Did you modify the file maybe?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by Donald Duck »

MartinVee wrote:Can you post a mininimal example that reproduces the problem?
The most minimal Irrlicht code reproduces the problem when compiled with XCode compiler on Mac (on Windows and Linux it works just fine):

Code: Select all

#include <irrlicht.h>
int main(){
    irr::createDevice(irr::video::EDT_OPENGL);
    return 0;
}
In case this isn't enough, I've uploaded the libIrrlicht.a file here: http://www.files.com/shared/591c703f93c ... icht.a.zip. I compiled this file with XCode 7.3.1 from the project MacOSX.xcodeproj provided in the Irrlicht download (Irrlicht 1.8.4). All I changed in that project was to compile it with compatibility mode for Mac 10.8 and added the flag -stdlib=libc++.
Last edited by Donald Duck on Wed May 17, 2017 4:09 pm, edited 1 time in total.
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by Donald Duck »

CuteAlien wrote:Strange, the dev variable should be type IrrlichtDevice* and not CIrrDeviceMacOSX*. At least in my Irrlicht.cpp. Did you modify the file maybe?
I didn't change anything. Here is a ZIP file containing exactly the files I have (before I compiled anything whatsoever): http://www.files.com/shared/590e2c19ee8 ... -1.8.4.zip
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by CuteAlien »

Ok - but in that Irrlicht.cpp file there the dev variable is of type IrrlichtDevice*. You wrote earlier that it's of type irr::CIrrDeviceMacOSX* - and I don't know where you see that?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by MartinVee »

It runs the run() method from a variable called dev which is of type irr::CIrrDeviceMacOSX*, but it uses the constructor CIrrDeviceConsole.
Oh, that's what's wrong. You should have created dev with the following lines (in Irrlicht.cpp, around line 72) :

Code: Select all

 
        if (params.DeviceType == EIDT_OSX || (!dev && params.DeviceType == EIDT_BEST))
            dev = new CIrrDeviceMacOSX(params);
 
Do you actually compile those lines? I guess not, because if you did, they would definitely run. The SIrrlichtCreationParameters member DeviceType is set to EIDT_BEST by the constructor, so unless you specify otherwise (the example code you provided doesn't change that value), it should be called. Unless it's called, but returns NULL?

Like I said, I may be mistaken, because I don't have a MacOSX computer here. Can you put a breakpoint on line 72, and then step through to see if the constructor returns a NULL reference?

If the line 72 isn't compiled (the debugger won't stop on it), there's your problem.
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by Donald Duck »

MartinVee wrote:Like I said, I may be mistaken, because I don't have a MacOSX computer here. Can you put a breakpoint on line 72, and then step through to see if the constructor returns a NULL reference?

If the line 72 isn't compiled (the debugger won't stop on it), there's your problem.
Line 72 is for Windows, it's line 77 that's for Mac. But you're right that it compiled the wrong lines, it compiled line 102 instead of 77. I forced it to initialize dev with lines 76-77 instead of lines 101-102 by commenting lines 70-75 and lines 78-103 in Irrlicht.cpp. Then it initialized dev using the constructor of CIrrDeviceMacOSX as it should, but the problem is that it exited the constructor at line 523 in CIrrDeviceMacOSX.mm and therefore didn't initialize CursorControl on line 526. Apparently the problem is that the createWindow() function failed on line 519. How do I fix this?
CuteAlien wrote:Ok - but in that Irrlicht.cpp file there the dev variable is of type IrrlichtDevice*. You wrote earlier that it's of type irr::CIrrDeviceMacOSX* - and I don't know where you see that?
Sorry, my mistake. You're right, dev is of type IrrlichtDevice*. Now that I look back at it, I don't either know where I saw that. Anyway, it doesn't solve my problem.
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by MartinVee »

Did you try to step into :

Code: Select all

 
bool CIrrDeviceMacOSX::createWindow()
 
... to see why this function returns with false?

At this point, I'd like to ask you what exactly you're trying to achieve? Did you try to compile Irrlicht as a library and commented a few lines to hardcode for a console device? If that's the case, I feel I should tell you that you can't use OpenGL with the console device, as it's only implemented for Burning and Software. The CursorControl member is also only initialized if you're in a Windows NT console. And also, the MacOSX implementation in Irrlicht uses the Cocoa API, which is a GUI API, so I'm not sure what would happen if you tried to run it in a console environment.

Like I said earlier, I'm trying to help you by just reading the code, but it would greatly help us if you explained what you're basically trying to do.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by CuteAlien »

Sorry, I would also have to debug to figure out why createWindow() fails in your case. And unfortunately also got no OSX for testing myself :-(
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Donald Duck
Posts: 34
Joined: Sat Jan 21, 2017 6:51 pm
Location: Duckburg
Contact:

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by Donald Duck »

MartinVee wrote:At this point, I'd like to ask you what exactly you're trying to achieve?
I'm just trying to open an Irrlicht 3D window on Mac. I have an Irrlicht 3D game that uses OpenGL and that works fine on Windows and I'm trying to use the same code to make that game available for Mac. I'm not trying to do anything with any console device. Is there anything I need to do to tell the computer that I'm not coding for a console device?
CuteAlien wrote:And unfortunately also got no OSX for testing myself :-(
If you want and if your computer is good enough, you can install Mac on a virtual machine. That's what I did, my computer is Windows but I installed Mac on a virtual machine to be able to make my program available for Mac (unfortunately I'm having problems, that's why I'm here). If you're interested, here are instructions on how to do it: http://stackoverflow.com/a/43950736/4284627
MartinVee
Posts: 139
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: CursorControl pointer is null CIrrDeviceMacOSX.mm

Post by MartinVee »

Did you get to try stepping into createWindow to see what's going on?

Also, can you confirm that other OpenGL games are working inside your virtual machine?
Post Reply