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 3603 - Initial value of GL_UNPACK_ROW_LENGTH is set to window width
Summary: Initial value of GL_UNPACK_ROW_LENGTH is set to window width
Status: RESOLVED WORKSFORME
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.5
Hardware: x86_64 macOS 10.12
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-12 22:08 UTC by Patric Ljung
Modified: 2017-05-18 23:38 UTC (History)
1 user (show)

See Also:


Attachments
test program (1.32 KB, text/plain)
2017-05-18 23:37 UTC, Ryan C. Gordon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Patric Ljung 2017-03-12 22:08:16 UTC
For certain window sizes, such as 600, 640, and 800, the value of GL_UNPACK_ROW_LENGTH is left to the window width, causing a glTexImage operation to a potential seg. fault or just plain wrong.

When changing the initial window size to 610 or 820 the value is left at 0 (the initial value according to GL specs).

Work-around: Always set GL_UNPACK_ROW_LENGTH to zero (0) before uploading textures or image data to GL.

Only verified on MacOS 10.12.3 with SDL 2.0.5.
Comment 1 Alex Szpakowski 2017-03-17 02:49:22 UTC
SDL_Render's internal code sets the value of GL_UNPACK_ROW_LENGTH to the number of pixels in a SDL texture when you create or modify one.

SDL makes no guarantees about the OpenGL state for the context it uses for SDL_Render operations outside of internal SDL_Render API calls – using raw OpenGL with SDL_Render is effectively not supported.
Comment 2 Patric Ljung 2017-03-19 23:10:04 UTC
I am not using SDL_Render in my code at all. This is the code setting up SDL.

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Failed to initialize SDL: Error = %s\n", SDL_GetError());
        return -1;
    }

    app.window = SDL_CreateWindow("SDL GL Test",
                                  SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                                  SCREEN_WIDTH, SCREEN_HEIGHT,
                                  SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
    
    if (!app.window) {
        fprintf(stderr, "Failed to create window, error = %s\n", SDL_GetError());
        return -1;
    }

    // Create context
    // Use OpenGL 3.1 core
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 4);
    
    app.glcontext = SDL_GL_CreateContext(app.window);
    if (app.glcontext == NULL)
    {
        fprintf(stderr, "OpenGL context could not be created! SDL Error: %s\n", SDL_GetError());
    }


Followed by setting up glew

        // Initialize GLEW
        glewExperimental = GL_TRUE;
        GLenum glewError = glewInit();
        if (glewError != GLEW_OK) {
            fprintf(stderr,  "Error initializing GLEW! %s\n", glewGetErrorString(glewError));
        }
Comment 3 Ryan C. Gordon 2017-05-18 23:37:19 UTC
This does not reproduce here with SDL 2.0.5 or the latest in revision control, on macOS 10.12.4.

Is it possible GLEW, or something else, changed it?

(we _will_ change it with the Render API, but this attached program does not.)

--ryan.
Comment 4 Ryan C. Gordon 2017-05-18 23:37:43 UTC
Created attachment 2743 [details]
test program
Comment 5 Ryan C. Gordon 2017-05-18 23:38:14 UTC
Closing this bug, but please reopen it if we can find a way to reproduce it!

Thanks,
--ryan.