PDA

View Full Version : When i move sdl window the app freeze...



arthurprs
23-07-2007, 09:53 PM
When i move sdl window or the console window the app freeze... :? It's a problem on the code or what ?


program onMines;

{$APPTYPE CONSOLE}

uses
SysUtils,
SDL,
const_unit,
type_unit;

var
screen: PSDL_Surface;
ltick: Cardinal;
event: TSDL_Event;

const
fps = Trunc(1000 / 30);

begin
SDL_Init(SDL_INIT_VIDEO);
screen := SDL_SetVideoMode(640, 480, 24, SDL_SWSURFACE or SDL_DOUBLEBUF);
while True do
begin
ltick := SDL_GetTicks;
SDL_PollEvent(@event);
case event.type_ of
SDL_MOUSEMOTION:
Writeln(Format('mouse moved to x:%s | y:%s',[IntToStr(event.motion.x), IntToStr(event.motion.y)]));
SDL_KEYDOWN:
Writeln(Format('tecla : %s foi pressionada',[IntToStr(event.key.keysym.scancode)]) );
SDL_QUITEV:
Break;
end;
SDL_Delay(fps - (SDL_GetTicks - ltick));
end;
SDL_Quit;


end.



and,
how can i have the console window to make only sdl window visible?

Edit: one more question, in that code when i press "A" it recognizes many many A presses

technomage
23-07-2007, 10:35 PM
Hi

I have noticed that when moving an SDL window about the app freezes , I think this happens in most SDL apps. It's just something that happens (please someone correct me :) )

You can get rid of the Console window by removing the line


{$APPTYPE CONSOLE}


This can be handy sometimes so I tend to use


{$IFOPT D+}
{$APPTYPE CONSOLE}
{$ENDIF}


Which just enables the console window when debugging is enabled.

To stop the same key being handled you have to either

1) use SDL_EnableKeyRepeat to disable key repeat
2) use SDL_GetKeyState to get the current state of the keyboard then check if the key is pressed. (See Demos in JEDI-SDLv1.0 to examples)

Hope this helps

Dean

arthurprs
23-07-2007, 11:07 PM
Hi

I have noticed that when moving an SDL window about the app freezes , I think this happens in most SDL apps. It's just something that happens (please someone correct me :) )

You can get rid of the Console window by removing the line


{$APPTYPE CONSOLE}


This can be handy sometimes so I tend to use


{$IFOPT D+}
{$APPTYPE CONSOLE}
{$ENDIF}


Which just enables the console window when debugging is enabled.

To stop the same key being handled you have to either

1) use SDL_EnableKeyRepeat to disable key repeat
2) use SDL_GetKeyState to get the current state of the keyboard then check if the key is pressed. (See Demos in JEDI-SDLv1.0 to examples)

Hope this helps

Dean

Thanks xD

but the sdl window freezing is much bad =/

jasonf
24-07-2007, 12:09 AM
I've never noticed this.. (Sorry if this seems to contradict you Technomage)

Could you please post an example of the freezing app so I can test it? I'm a little worried that this might be an SDL issue which I'm not aware of using a different hardware setup to my own.

WILL
24-07-2007, 12:16 AM
I get the same thing as Dean. Actually what happens is that while the window is being dragged the program will freeze for that time. Let go of the mouse button to stop dragging it and the program will resume.

I believe it has to do with SDL's window management specifics.

arthurprs
24-07-2007, 12:36 AM
I get the same thing as Dean. Actually what happens is that while the window is being dragged the program will freeze for that time. Let go of the mouse button to stop dragging it and the program will resume.

I believe it has to do with SDL's window management specifics.

my english don't able me to understand if you proposed an solution or not :oops:

can you rewrite it ?

sorry :(

WILL
24-07-2007, 12:46 AM
I'm trying to say that your problem is normal. SDL does that.

arthurprs
24-07-2007, 12:58 AM
I'm trying to say that your problem is normal. SDL does that.

But it Freezes completly :? , it don't recover... it crashes..

its normal :shock: ?

Edit: its possible to create a surface based on a bitmap on memory ?

WILL
24-07-2007, 04:29 AM
Well, crashing like that is not normal... :?

I think you might be either doing something wrong/unconventional(not normal) in your code or you something might be corrupt somewhere...


When you create a SDL_Surface thats basically what you're doing. You're making achunk of memory that is the actual color data. You just have to know what pixel format you want to use and stick to it.

arthurprs
24-07-2007, 04:47 AM
Well, crashing like that is not normal... :?

I think you might be either doing something wrong/unconventional(not normal) in your code or you something might be corrupt somewhere...


When you create a SDL_Surface thats basically what you're doing. You're making achunk of memory that is the actual color data. You just have to know what pixel format you want to use and stick to it.

:? looks simple, how can i do it ?

DarknessX
15-08-2007, 05:41 AM
I get the exact same problem with the code used in my post. The entire Jedi-SDL window is unstable. It cannot be moved.

arthurprs
15-08-2007, 10:55 PM
I get the exact same problem with the code used in my post. The entire Jedi-SDL window is unstable. It cannot be moved.
i have solved it, it was a code mistake in mainloop

DarknessX
16-08-2007, 05:51 AM
Can you post the solution please? I was fairly sure that's where the problem was (I'm only trying to actually draw a map right now) so it didn't matter, but I'd rather not have to experiment to fix it :)

arthurprs
16-08-2007, 05:02 PM
Can you post the solution please? I was fairly sure that's where the problem was (I'm only trying to actually draw a map right now) so it didn't matter, but I'd rather not have to experiment to fix it :)
Post you main loop, its better :)

Im my case the problem was "Wait for next frame" code

DarknessX
16-08-2007, 07:16 PM
Well my main loop contains no readln or anything, it just displays the graphics over and over again. It doesn't pause or anything... yet.

arthurprs
16-08-2007, 08:56 PM
Well my main loop contains no readln or anything, it just displays the graphics over and over again. It doesn't pause or anything... yet.
So try to manage events at begin of main loop


//declare
event: TSDL_Event; // sdl event

procedure Manageinput;
begin
while SDL_PollEvent(@event) > 0 do
if event.type_ = SDL_QUITEV then
dosomething;
end;
end;


and also add


SDL_Delay(35);

to end of main loop