changing cursor to image woe...T^T

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Echilon
Posts: 6
Joined: Tue Jan 17, 2012 5:18 am

changing cursor to image woe...T^T

Post by Echilon »

I followed the method of how to change the cursor to be an image from the manual, but I end up with this instead:

First-chance exception at 0x013d3649 in Com S 309 Project.exe: 0xC0000005: Access violation reading location 0x0021005d.
Unhandled exception at 0x013d3649 in Com S 309 Project.exe: 0xC0000005: Access violation reading location 0x0021005d.

my code is as follows:(not all of my code)

Code: Select all

 
        TitleScreen title(device);
        ISceneManager* smgr = title.ChangeScene();
        IGUIEnvironment* guien = title.ChangeText();
        ICursorControl* cursor = device->getCursorControl();
 
        cursor->setVisible(false);
 
        IGUIImage* image = guien->addImage(driver->getTexture("../media/cursor.tga"), position2d<s32>(0, 0));
 
        ICameraSceneNode* camera = smgr->addCameraSceneNode(0, core::vector3df(0, 0, 0), core::vector3df(0, 0, -5));
 
        while(device->run()){
 
                if(currentState == -1){
                        break;
                }
 
                if(currentState == STATE_1 && receiver.IsKeyDown(KEY_RETURN)){
                        currentState = STATE_2;
                }
 
                if(currentState == STATE_2 && receiver.GetMouseState().LeftButtonDown){
                        currentState = STATE_3;
                }
 
                if(currentState == STATE_2 && receiver.IsKeyDown(KEY_ESCAPE)){
                        currentState = -1;
                }
 
                if(currentState == STATE_3 && receiver.IsKeyDown(KEY_ESCAPE)){
                        currentState = -1;
                }
 
//              if(currentState == STATE_4 && receiver.IsKeyDown(KEY_ESCAPE)){
//                      currentState = STATE_3;
//              }
 
//              if(currentState == STATE_4 && receiver.GetMouseState().LeftButtonDown){
//                      currentState= STATE_2;
//              }
 
                if(currentState != lastState){
                        if(currentState == STATE_2){
                                mainMenu menu(device);
                                smgr = menu.ChangeScene();
                                guien = menu.ChangeText();
                                lastState = currentState;
                        }else if(currentState ==STATE_3){
                                GameWorld game(device);
                                smgr = game.ChangeScene();
                                guien->clear();
                                camera = game.ChangeCamera(keyMap);
                                lastState = currentState;
                        }else if(currentState == STATE_4){
                                guien->clear();
                                guien->addStaticText(L"You are now in Game Menu\n press escape to get back to Game World, or left click to go back to Main Menu.", rect<s32>(480, 200, 1440, 300), false, true);
                                lastState = currentState;
                        }
                }
 
                driver->beginScene(true, true, SColor(255, 100, 101, 140));
 
                int x = cursor->getPosition().X;
                int y = cursor->getPosition().Y;
                image->setRelativePosition(position2di(x, y));
 
                smgr->drawAll();
                guien->drawAll();
 
                driver->endScene();
        }
 
        device->drop();
 
        return 0;
}
 
does anyone have any suggestion on how to fix it, or should I abandon this method? o.O

edit: put code tags in...sorry
Last edited by Echilon on Sun Feb 19, 2012 1:12 am, edited 1 time in total.
darksmaster923
Posts: 51
Joined: Tue Jan 02, 2007 11:04 pm
Location: huntington beach

Re: changing cursor to image woe...T^T

Post by darksmaster923 »

please use code tags
Programmers are merely tools to convert caffeine into code.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: changing cursor to image woe...T^T

Post by greenya »

Maybe save the call

Code: Select all

driver->getTexture("../media/cursor.tga")
to a variable, then test it on null.
darksmaster923
Posts: 51
Joined: Tue Jan 02, 2007 11:04 pm
Location: huntington beach

Re: changing cursor to image woe...T^T

Post by darksmaster923 »

Going by your post, I assume if you comment out the

Code: Select all

image->setRelativePosition(position2di(x, y));
line it works?

Which line does the error point to, by the way?
Programmers are merely tools to convert caffeine into code.
Echilon
Posts: 6
Joined: Tue Jan 17, 2012 5:18 am

Re: changing cursor to image woe...T^T

Post by Echilon »

darksmaster923 wrote:Going by your post, I assume if you comment out the

Code: Select all

image->setRelativePosition(position2di(x, y));
line it works?
yes, that line does work ^^.
Which line does the error point to, by the way?
if I remember correctly, the line that the error was pointing to was a line that was calling the setVisible function, which I took out(quite literally I reverted to an older version of my code).
what happened was that I would change states and the program would freeze, as if it went into an infinite loop. Then I made a few changes which got me the error message.
Echilon
Posts: 6
Joined: Tue Jan 17, 2012 5:18 am

Re: changing cursor to image woe...T^T

Post by Echilon »

greenya wrote:Maybe save the call

Code: Select all

driver->getTexture("../media/cursor.tga")
to a variable, then test it on null.
what would I save that call to, what type? and when you say test it on null you mean replace that call with null, correct?
CuteAlien
Admin
Posts: 10045
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: changing cursor to image woe...T^T

Post by CuteAlien »

The error message is pretty useless (just tells that you access memory which you shouldn't access). The exact line where it happens is what matters.
And what greenya told you was that you should put the result of driver->getTexture in a variable - and the type is certainly exactly the type which getTexture returns (look it up in the manual). And testing on null simply means you should test in the next line if that variable now contains a valid (non-null) pointer or not. Which you can do with an 'if' - which you either know how to do or you should really, really first work your way through some more c++ tutorials before starting 3D development.

Also on a sidenode... if you update to svn trunk version of Irrlicht you can get support for hardware-cursors including an example which is better as software-cursors are restricted to your framerate.
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
Post Reply