OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Error Program exited with code -1073741819 - DerelictSDL2

  • Thread starter Thread starter nocluey
  • Start date Start date
N

nocluey

Guest
I'm developing an application using SDL2 and SDL2_image in D, and I'm encountering an access violation error -1073741819 when I attempt to run my program. I've included the relevant code below. The error occurs when I try to initialize SDL2_image or when creating the window, but I am not certain which part is specifically causing the issue.

Code:
import std.stdio;
import derelict.sdl2.sdl;
import derelict.sdl2.image;

void main() {
    // Load SDL2 dynamically
    DerelictSDL2.load();

    // Initialize SDL_image for JPG support
    if (IMG_Init(IMG_INIT_JPG) & (IMG_INIT_JPG != IMG_INIT_JPG)) {
        writeln("Failed to initialize SDL_image: ", SDL_GetError());
        return;
    }

    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        writeln("Failed to initialize SDL: ", SDL_GetError());
        return;
    }

    // Create window
    SDL_Window* window = SDL_CreateWindow("Hello SDL2",
                                          SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                          500, 500, SDL_WINDOW_SHOWN);
    if (!window) {
        writeln("Failed to create window: ", SDL_GetError());
        SDL_Quit();
        return;
    }

    // Create renderer with hardware acceleration and synchronized with the refresh rate
    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
    if (!renderer) {
        writeln("Failed to create renderer: ", SDL_GetError());
        SDL_DestroyWindow(window);
        SDL_Quit();
        return;
    }

    // Load image and create texture
    SDL_Surface* image = IMG_Load("fdcae74b5ad91e309aa03020c7ea4f26.jpg");
    if (!image) {
        writeln("Failed to load image: ", SDL_GetError());
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        return;
    }
    SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, image);
    if (!texture) {
        writeln("Failed to create texture: ", SDL_GetError());
        SDL_FreeSurface(image);
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        return;
    }

    // Event handling loop
    SDL_Event event;
    bool running = true;
    while (running) {
        while (SDL_PollEvent(&event) != 0) {
            if (event.type == SDL_QUIT) {
                running = false;
            }
        }
    }

    // Clean up
    SDL_DestroyTexture(texture);
    SDL_FreeSurface(image);
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
}

I've Ensured all libraries are correctly installed and paths are properly configured. Added comprehensive error checks after each operation that interacts with SDL. Verified that the image file exists and is accessible.
<p>I'm developing an application using SDL2 and SDL2_image in D, and I'm encountering an access violation error -1073741819 when I attempt to run my program. I've included the relevant code below. The error occurs when I try to initialize SDL2_image or when creating the window, but I am not certain which part is specifically causing the issue.</p>
<pre><code>import std.stdio;
import derelict.sdl2.sdl;
import derelict.sdl2.image;

void main() {
// Load SDL2 dynamically
DerelictSDL2.load();

// Initialize SDL_image for JPG support
if (IMG_Init(IMG_INIT_JPG) & (IMG_INIT_JPG != IMG_INIT_JPG)) {
writeln("Failed to initialize SDL_image: ", SDL_GetError());
return;
}

// Initialize SDL
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
writeln("Failed to initialize SDL: ", SDL_GetError());
return;
}

// Create window
SDL_Window* window = SDL_CreateWindow("Hello SDL2",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
500, 500, SDL_WINDOW_SHOWN);
if (!window) {
writeln("Failed to create window: ", SDL_GetError());
SDL_Quit();
return;
}

// Create renderer with hardware acceleration and synchronized with the refresh rate
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!renderer) {
writeln("Failed to create renderer: ", SDL_GetError());
SDL_DestroyWindow(window);
SDL_Quit();
return;
}

// Load image and create texture
SDL_Surface* image = IMG_Load("fdcae74b5ad91e309aa03020c7ea4f26.jpg");
if (!image) {
writeln("Failed to load image: ", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return;
}
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, image);
if (!texture) {
writeln("Failed to create texture: ", SDL_GetError());
SDL_FreeSurface(image);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return;
}

// Event handling loop
SDL_Event event;
bool running = true;
while (running) {
while (SDL_PollEvent(&event) != 0) {
if (event.type == SDL_QUIT) {
running = false;
}
}
}

// Clean up
SDL_DestroyTexture(texture);
SDL_FreeSurface(image);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
</code></pre>
<p>I've Ensured all libraries are correctly installed and paths are properly configured.
Added comprehensive error checks after each operation that interacts with SDL.
Verified that the image file exists and is accessible.</p>
Continue reading...
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top