We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 258

Summary: Window repositioning problem when menu loaded
Product: SDL Reporter: Charles MacDonald <chamacd>
Component: videoAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: minor    
Priority: P2    
Version: 1.2.10   
Hardware: x86   
OS: Windows (XP)   

Description Charles MacDonald 2006-06-21 12:29:23 UTC
Using SDL 1.2.10 and mingw, successive calls to SetVideoMode() when a Windows menu is loaded cause the window to be displaced vertically by the number of pixels that comprise the menu height. This makes the window scroll downwards each time, until it is off-screen.

Here's a test case. Press SPACE to call SetVideoMode() with the same window dimensions. If you comment out SetMenu(), no menu is loaded and the window remains at the same position on the desktop.

#include <stdio.h>
#include <windows.h>
#include <SDL.h>
#include <SDL_syswm.h>
SDL_Surface *screen;

void resize_display(void) {
    screen = SDL_SetVideoMode(320, 240, 16, SDL_SWSURFACE | SDL_ANYFORMAT);
    if(SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, rand(), rand(), rand()));
    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
    SDL_UpdateRect(screen, 0, 0, 0, 0);
}

int main (int argc, char *argv[]) {
    SDL_SysWMinfo wminfo;
    HMENU mnuMain, mnuSub;
    char *keystate;
    int running = 1;
    SDL_Event event;

    SDL_Init(SDL_INIT_VIDEO);
    SDL_VERSION(&wminfo.version);
    SDL_GetWMInfo(&wminfo);

    mnuMain = CreateMenu();
    mnuSub = CreateMenu();
    AppendMenu(mnuSub, MF_STRING, 40001, "&Hello World");
    AppendMenu(mnuMain, MF_POPUP, (UINT_PTR)mnuSub, "File");
    SetMenu(wminfo.window, mnuMain);    
    resize_display();

    while(running) {
        keystate = SDL_GetKeyState(NULL);

        if(keystate[SDLK_SPACE]) {
            resize_display();
        }

        if(keystate[SDLK_ESCAPE])
            running = 0;

        while(SDL_PollEvent(&event)) {
            if(event.type == SDL_QUIT)
                running = 0;
        }
    }

    return 0;
}
Comment 1 Sam Lantinga 2006-06-24 00:31:27 UTC
This is fixed in subversion, thanks!