in reply to Re^2: SDL/SDLx issue with application resizing
in thread SDL/SDLx issue with application resizing

In SDL::Event I found this:

Window resize events resize_w, resize_h When SDL_RESIZABLE is passed as a flag to SDL_SetVideoMode the user is + allowed to resize the applications window. When the window is resized an SDL_VIDEORESIZE is reported, with the new window width and height values stored in the resize structure's resize_w and resize_h. When an + SDL_VIDEORESIZE is received the window should be resized to the new dimensions using SDL_SetVideoMode.

In your program it looks like you have everything except the last part where it says to use SDL_SetVideoMode.

I couldn't find any examples that use that but I did find an example included in SDL called examples/cookbook/1.pl that uses SDL::Video::set_video_mode(320, 320, 32, SDL_SWSURFACE );

The documentation for SDL::Video::set_video_mode() shows that function seems to be what you need:

SDL_RESIZABLE Create a resizable window. When the window is resized by the user a SDL_VIDEORESIZE event is generated and SDL::Video::set_video_mode can be called again with the new size.

There are more details there on how to call SDL::Video::set_video_mode().

Your application looks interesting. Let us know how it works out. Good luck!

Update:

After looking at your application again and looking at the contents of App.pm I notice the resize() function you use calls SDL::Video::set_video_mode() so it seems like you've done it correctly. My comments above were not very helpful it seems.

Replies are listed 'Best First'.
Re^4: SDL/SDLx issue with application resizing
by Garden Dwarf (Beadle) on Feb 01, 2019 at 07:28 UTC

    Hello Lotus1,

    Thanks for having tried, I appreciate :)

    The error message above suggest an issue with DirectDraw (DDraw), maybe something related with the driver. I'll look at this, but first queries on Google do not return much answers. Stay tuned.

      Hi Garden Dwarf,

      On my home computer I was able to run your application and I also sometimes received the same error message with the crash. Sometimes it crashes without an error but I also had a few cases where it successfully resized. I found a comment somewhere that said on Windows platforms you need to reinitialize some things after the resize. The fact that I could resize a few times makes me think it isn't a driver issue but some kind of memory allocation or math error due to resizing.

      I created a simpler program to demonstrate this error by adding the resizeable option to one of the examples that come with the SDL module. I'm planning to try it tonight on Linux to see what happens.

      This isn't my tested version but should be close.

      #modified version of SDL-2.548/examples/SDLx/app.pl use SDL::Event; use SDLx::App; my $app = SDLx::App->new( title => "Lines", width => 640, height => 480, resizeable >'on', ); sub draw_lines { $app->draw_line( [ 0, 0 ], [ rand( $app->w ), rand( $ +app->h ) ], 0xFFFFFFFF ); $app->update(); } sub event_handle { my $event = shift; my $app = shift; $app->stop if ( $event->type == SDL_QUIT ); if($event->type==SDL_VIDEORESIZE){ $app->resize($event->resize_w,$event->resize_h); } } $app->add_event_handler( \&event_handle ); $app->add_show_handler( \&draw_lines ); $app->run();

        I made my code independent of the video buffer. All is computed in "Virtual" buffers at a fixed width/height and then scaled to fit the screen (Rotozoom module). So I don't see any issue with maths.

        In the meantime, I was able to observe the same behavior as you reported (time to time resizing works, time to time resizing crashes with a message, and time to time resizing crashes without any error message). It is then quite difficult to investigate, as the result may vary between tries.

        I really hope you will find something with your tests. And even if you don't, thanks again for your time ;)

        Update

        I've tried the opengl example from the Examples folder of the SDL installation (reason: it seems to uses opengl instead of DirectX) and allowed the window to be resized. Result: I can change the size without any issue (note that the image is not resized along with the window, but I don't think it does matter, doesn't it?).