Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SetCursorPosition Crash  (Read 2215 times)

0 Members and 1 Guest are viewing this topic.

msteele

  • Newbie
  • *
  • Posts: 12
    • View Profile
SetCursorPosition Crash
« on: April 03, 2011, 05:59:55 am »
nFrame represents the frame number within the main loop.

This works
Code: [Select]
if (nFrame % 2 == 0) {Window.SetCursorPosition(15, 45);}

This produces a spinning beach-ball of death.
Code: [Select]
Window.SetCursorPosition(15, 45);

Why is this?

Also, I would like to use this to get the relative movement of the mouse without it moving. For this reason, integer values of the mouse do not work as the mouse rarely moves even a pixel in the frame(s), what's the best way to get high-precision mouse movement information?

[SFML2, Snow Leopard]

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
SetCursorPosition Crash
« Reply #1 on: April 03, 2011, 09:03:55 am »
Can you provide a minimal and complete code that reproduce the problem ? Thanks.

Quote
Also, I would like to use this to get the relative movement of the mouse without it moving.
I might have misunderstood but how can a mouse move without moving ? If you want to get the mouse movement you can do something like :
Code: [Select]

initialize (someX,someY) // values arbitrary chosen
In you event loop :
if event is mouse move then
  store the new position of the mouse in (x,y)
  compute the difference between (x,y) and (someX,someY) // that's the mouse movement
  move the mouse to (someX,someY)

In you logic code part :
do something nice with the movement (if any at that time).

No need of % 2 stuff.

Quote
For this reason, integer values of the mouse do not work as the mouse rarely moves even a pixel in the frame(s), what's the best way to get high-precision mouse movement information?
Yes. (I don't think the mouse can go between two pixels.)
SFML / OS X developer

msteele

  • Newbie
  • *
  • Posts: 12
    • View Profile
SetCursorPosition Crash
« Reply #2 on: April 03, 2011, 09:45:29 pm »
Regarding the integer stuff, think of the mouse not as a pointer, but as a physical joystick-like thing. It makes perfect sense to have an input that represents the speed of a finger moving over it.

As for minimal code... I tried.
The line you're looking for is this:
Code: [Select]
if (nFrame %1 == 0) { // <-- The offending number

When that number is 2:
- mouse stays in center
- square moves up
- escape events are caught

When that number is 1:
- mouse stays in center
- the square moves up (so I guess the loop has not crashed)
- escape events are not caught
- spinning beach ball of death

Code: [Select]
#include <iostream>

#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

int main(int argc, char** argv) {

sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
sf::ContextSettings OGLContext(
24, // depth
8, // stencil
4, // antialiasing
2, // major
0); // minor
float WIDTH = DesktopMode.Width;
float HEIGHT = DesktopMode.Height;
float AspectRatio = float(WIDTH)/float(HEIGHT);
sf::Window Window(DesktopMode, "SFML Window", sf::Style::Fullscreen, OGLContext);
Window.SetActive();

const sf::Input& WInput = Window.GetInput();
Window.ShowMouseCursor(true);
Window.SetCursorPosition(WIDTH/2, HEIGHT/2);

// glSetup
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

// glPerspective
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.f, AspectRatio, .1f, 500.f);
glMatrixMode(GL_MODELVIEW);

// Setup for event handling
sf::Event Event;

bool Running = true;

// Main Loop
unsigned int nFrame = 0;
while (Running) {
++nFrame;

// Event Handling
while (Window.GetEvent(Event)) {
if (Event.Type == sf::Event::Closed)
{Running = false;}
else if (Event.Type == sf::Event::KeyPressed) {
if (Event.Key.Code == sf::Key::Escape)
{Running = false; }
}
}

// Move Mouse
if (nFrame %1 == 0) { // <-- The offending number
Window.SetCursorPosition(WIDTH/2, HEIGHT/2);
}

// Rendering Setup
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

// Draw a square with colors
glPushMatrix();
glTranslatef(5.f, 0.f, -10.f);
glTranslatef(0, nFrame/float(100), 0);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glPopMatrix();

// Display Window
Window.Display();

}

return EXIT_SUCCESS;
}

 

anything