Genymobile / Genymobile/scrcpy

SDL_main error code

Open
#3,532 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
150k
Forks
13.7k
Avg merge
4d 13h
Merged PRs (30d)
2

Description

#include
#include

#define WINDOW_WIDTH (640)
#define WINDOW_HEIGHT (480)

// speed in pixels/second
#define SCROLL_SPEED (300)

int main(void)
{
// attempt to initialize graphics and timer system
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0)
{
printf("error initializing SDL: %s\n", SDL_GetError());
return 1;
}

SDL_Window* win = SDL_CreateWindow("Hello, CS50!",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
WINDOW_WIDTH, WINDOW_HEIGHT,0);
if (!win)
{
printf("error creating window: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}

// create a renderer, which sets up the graphics hardware
Uint32 render_flags = SDL_RENDERER_ACCELERATED;
SDL_Renderer* rend = SDL_CreateRenderer(win, -1, render_flags);
if (!rend)
{
printf("error creating renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(win);
SDL_Quit();
return 1;
}

// load the image into memory using SDL_image library function
SDL_Surface* surface = IMG_Load("resources/hello.png");
if (!surface)
{
printf("error creating surface\n");
SDL_DestroyRenderer(rend);
SDL_DestroyWindow(win);
SDL_Quit();
return 1;
}

// load the image data into the graphics hardware's memory
SDL_Texture* tex = SDL_CreateTextureFromSurface(rend, surface);
SDL_FreeSurface(surface);
if (!tex)
{
printf("error creating texture: %s\n", SDL_GetError());
SDL_DestroyRenderer(rend);
SDL_DestroyWindow(win);
SDL_Quit();
return 1;
}

// struct to hold the position and size of the sprite
SDL_Rect dest;

// get the dimensions of texture
SDL_QueryTexture(tex, NULL, NULL, &dest.w, &dest.h);

// position the sprite at the bottom center of the window
// origin is the top left corner, positive y is down
dest.x = (WINDOW_WIDTH - dest.w) / 2;

// require float resolution for y position
float y_pos = WINDOW_HEIGHT;

// animation loop
while (dest.y >= -dest.h)
{
// clear the window
SDL_RenderClear(rend);

// set the y position in the struct
dest.y = (int) y_pos;

// draw the image to the window
SDL_RenderCopy(rend, tex, NULL, &dest);
SDL_RenderPresent(rend);

// update sprite position
y_pos -= (float) SCROLL_SPEED / 60;

// wait 1/60th of a second
SDL_Delay(1000/60);
}

// clean up resources before exiting
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(rend);
SDL_DestroyWindow(win);
SDL_Quit();
}

I'm attempting to get a sprite loaded onto an sdl screen but on launching the code i get a conflicting types for SDL_main. I'm compiling and editing on codeblocks. please help!

Contributor guide

No contributing guide indexed for this repository

Research direction

The report contains only a standalone C snippet and does not name a scrcpy file, test, or entry point. First establish whether the SDL_main error is reproducible in this repository; done would require a repository-specific reproduction and a confirmed fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
desktop
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
10/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.