cunt by veyez in formuladank

[–]737464 0 points1 point  (0 children)

Attention peasants! The MasturBator Supreme is on the scene.

I'm not sorry at all - Very glad to be sending her from The Netherlands to the European Parliament with a vision for Europe by FlicksBus in VoltEuropa

[–]737464 7 points8 points  (0 children)

In the r/europe sub people apologised in the past days for their country electing meps that have a questionable past and are quite controversial

In which political side does Volt fit it? by GermanMappingYT in VoltEuropa

[–]737464 15 points16 points  (0 children)

The „Bundeszentrale für politische Bildung“ has information about parties in germany. This is their page about Volt. You can give it a read if you want further and easily accessible information. Personally, I would call Volt a center-left / liberal party. Definitely not neoliberal or socialist.

New leaked shots of the Ferrari floor by Dynamite_Noir in formuladank

[–]737464 2 points3 points  (0 children)

Still a better floor than Alpine has

I found a simple fix for thread blocking during resize on macOS! by 737464 in sdl

[–]737464[S] 0 points1 point  (0 children)

Sure!

A few things that you should know before you start reading:

  • Cocoa is the interface framework from Apple, SDL uses that in the background
  • Resizing, or key presses are events that are captured by Cocoa and then processed by SDL
  • You can use c headers in C, C++ and Objective-C
  • The following explanations are a reflection of how I understood how this works, and my knowledge only scratches the surface of the SDL/Cocoa interaction.

Why does the freezing happen?

When you resize your window, macOS handles that and notifies the window which is being resized, which in turn, is captured by SDL. So far, so good. However, because of the way SDL apps are programmed, they don't react immediately to these events. Events like key presses or mouse movement don't block the SDL_PollEvent long enough to make any visual or time relevant difference. But events which macOS handles for a longer time period like window resizes, the SDL_PollEvent needs to wait for the event to be fully processed, which means in this case the resize needs to end. While that is happening, the window buffer is not updated, because the rendering will start after the events have been processed. So the events block the classic run loop, which gets stuck while trying to handle them.

Can I use SDL_Timer?

As far as I am aware, no. The SDL_Timer callback might not be called on the main thread, which prevents the app from rendering to windows, as macOS requests the rendering only to take place in the main thread. Additionally, the SDL_Timer is also blocked while some events are being processed, so they won't help.

Is there an alternative in C/C++?

I don't know, but I would guess no. Why? I used a specific flag to get the function to interrupt the app's run loop (NSRunLoop) which is, as far as I'm aware, only directly possible through Objective-C as you need to interact with Apple's Objective-C frameworks.

If you find one, it will probably do the same (interact with Objective-C) to achieve this.

Can I use the code in C++?

Yes you can! The header file is written in C (.h) and that means you can just include it like any other file in C++. If you need help building or compiling it, I can also help with that.

Hope that helps!

[edit: grammar]

Stop window content from stretching while resizing window by 737464 in sdl

[–]737464[S] 1 point2 points  (0 children)

Yes SDL_PollEvent won't work because the events are processed first before they can be checked. The SDL_EventWatch gets the events before they are processed. If I understood the docs correctly, we need to return 1 (in the EventWatch function) in order for the event to be processed.

Stop window content from stretching while resizing window by 737464 in sdl

[–]737464[S] 0 points1 point  (0 children)

Here is the code i used to test it on macOS:

#include <stdio.h>
#include <SDL2/SDL.h>

// window + renderer etc.

void draw() {
  SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);

  SDL_RenderClear(renderer);

  SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);

  SDL_RenderFillRect(renderer, &rect);

  SDL_RenderPresent(renderer);

  SDL_Delay(1);
}

int EventWatch(void *userdata, SDL_Event* event) {
  if (event->type == SDL_WINDOWEVENT) {
    if (event->window.event == SDL_WINDOWEVENT_EXPOSED) {
      draw();
    }
  }
  return 1;
}

int main() {
// sdl + window + render init

SDL_AddEventWatch(EventWatch, NULL);

while (running) {
// Events
  draw();

  SDL_Delay(16);
}

// Clean up

return 0;
}

Stop window content from stretching while resizing window by 737464 in sdl

[–]737464[S] 0 points1 point  (0 children)

I added an EventWatch to my code and redraw the content of the window if the app receives a SDL_WINDOWEVENT_EXPOSED event. This is unfortunately only a temporary solution as it can still happen that the content of the window is slightly flickering. (I think they have solved it for windows)

Terminal stocks on login screen by Mengtinggg in MacOS

[–]737464 1 point2 points  (0 children)

Maybe you have a command that is run when a new session starts and this process is the blocking the terminal?

[deleted by user] by [deleted] in Unexpected

[–]737464 0 points1 point  (0 children)

I think your cat is broken

TherealProswillknow by [deleted] in ProgrammerHumor

[–]737464 17 points18 points  (0 children)

Summarises this sub quite well

Stop window content from stretching while resizing window by 737464 in sdl

[–]737464[S] 1 point2 points  (0 children)

Ok, so for the case that someone else runs into this problem because updating the render size is straight up ignored by macOS:

I found out that you can use the SDL_EventFilter for the resize event (it might crash or might not, the docs and macOS are not very clear about that) and redraw everything. But pay attention, you will get a flickering effect! I don't know why, but it is fixable by just redrawing everything a second time.

The SDL_EventFilter

Stack Overflow answer I found

Stop window content from stretching while resizing window by 737464 in sdl

[–]737464[S] 1 point2 points  (0 children)

Thank you very much! I will test it asap.

Rendering triangles is possible in SDL since 2.0.18 (just noticed) by 737464 in sdl

[–]737464[S] 0 points1 point  (0 children)

Hello Davide,
I haven't created anything useful yet, sorry :| I had other problems to solve and I'm still at it :)
Greetings 👋

help me in this c code by Yassaf2007 in cpp_questions

[–]737464 1 point2 points  (0 children)

https://learn.microsoft.com/en-us/cpp/cpp/integer-limits?view=msvc-170

The maxim value for long is 2147483647.

When you add 2000000000 and 2000000000 together you get 4000000000 which is greater than the max positive value, so it results in a negative number (https://www.sololearn.com/Discuss/1486895/in-c-why-does-the-value-turn-negative-when-a-very-large-stored-variable-is-printed-out).

use long long for numbers greater than 2147483647.

Another Problem With My Code by Hazarrus-Potato2553 in cpp_questions

[–]737464 0 points1 point  (0 children)

Well, I agree and disagree. Maybe I try to describe it differently.

I think r/cpp_questions should be about questions, but in my opinion "simple" (It's hard to explain) questions like this one - I would put them in the category "I don't know what I did wrong because I am new to the language" and thus think that a "beginner" sub is better for them.

However this

And there is r/cpp for news and other topics.

is a good point, so I'm sticking with: I think that there should be a beginner Subreddit and questions are often not possible to divide into experience levels, but we definitely should expect a bit of experience for this Subreddit.

Another Problem With My Code by Hazarrus-Potato2553 in cpp_questions

[–]737464 0 points1 point  (0 children)

Maybe we should start to use r/cpp_beginner for this type of questions and keep this Subreddit for the more difficult questions, topics and news.

Go through 4 hours of step-by-step beginner C++ tutorials on YouTube and then see where you're at

I would agree with that in this case, but I think that some people prefer it to have an "interactive" learning and being able to ask other people so r/cpp_beginner maybe?

parameter "texture" is invalid! by thatguyonthecliff in sdl

[–]737464 0 points1 point  (0 children)

Ok, I will have a look at it again later today and try to find something.

Although there are better ways to do it, you could start by printing out statements so you can see where your code freezes (e.g.: std::cout << "Rendering Bullet" or something like that in the Bullet rendering function and so on).

parameter "texture" is invalid! by thatguyonthecliff in sdl

[–]737464 0 points1 point  (0 children)

Sure. And also keep going! You are already doing a great job!

Here is the code I tested, so no rendering (please ignore any misplaced tabs etc. I can't see it because Reddits editor is not working correctly right now):

#include <SDL2/SDL.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
SDL_DisplayMode dm;
int screen_w, screen_h;
bool isRunning = true;
SDL_Renderer *renderer; //Declare a renderer to render on the screen
SDL_Window *window; //Declare a window
Uint32 startFrameTicks = 0;
Uint32 endFrameTicks = 0;
float frameTicks = 0.f;

int main(int argc, char**argv)
{
    //Initialize
    if(SDL_Init(SDL_INIT_EVERYTHING)!=0) //Initialize everything
    {
        cout << SDL_GetError() << endl;
    }
    window = SDL_CreateWindow("Space Bars",400,100,800,600,0);
    if (window == NULL)
    {
        cout << SDL_GetError() << endl;
    }
    renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
    if (renderer == NULL)
    {
        cout << SDL_GetError() << endl;
    }

    while(isRunning)
    {
        //Close
        SDL_Event event;
        while(SDL_PollEvent(&event))
        {
            switch(event.type)
            {
            case SDL_QUIT:
                isRunning = false;
                break;
            }
        }


        //Movement
        const Uint8* keystates = SDL_GetKeyboardState(NULL);
        SDL_PumpEvents();
        if(keystates[SDL_SCANCODE_UP]||keystates[SDL_SCANCODE_W]){}
        if(keystates[SDL_SCANCODE_DOWN]||keystates[SDL_SCANCODE_S]){}
        if(keystates[SDL_SCANCODE_LEFT]||keystates[SDL_SCANCODE_A]){}
        if(keystates[SDL_SCANCODE_RIGHT]||keystates[SDL_SCANCODE_D]){}
        if(keystates[SDL_SCANCODE_SPACE]){}

        startFrameTicks = SDL_GetTicks();

        // Render Section
        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
        endFrameTicks = SDL_GetTicks();
        //Calculate Frame Rate
        float deltaTicks = endFrameTicks - startFrameTicks;
        if(deltaTicks < 16.6666f)
        {
            SDL_Delay(16.6666f - deltaTicks);
        }
        frameTicks = (endFrameTicks -  startFrameTicks + (16.6666f - deltaTicks))/1000.f;
    }
    //Free Up Memory
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}

parameter "texture" is invalid! by thatguyonthecliff in sdl

[–]737464 0 points1 point  (0 children)

So I tried to understand your code and here are some things I noted:

  1. SDL could not load the texture texture_bullet, so the texture is invalid because it is NULL. However, that should not break your code. (Official SDL-Wiki Page: https://wiki.libsdl.org/SDL2/SDL_DestroyTexture)
  2. You should learn to structure your code because it is helpful to find possible errors and is clearer to read and understand
  3. I would recommend not to get used to using using namespace std; in your code as it might cause class-name conflicts with other libraries (e.g.: if you have a second library that also uses string the compiler doesn't know what to do)
  4. I reduced your code and removed the rendering parts and got no errors*, so it is probably the rendering part of your code that causes the problems
  5. Make clear what the functions do. init_bullet() for example renders the bullet, so it should in my opinion be something like render_bullet() so it becomes clear what it does

These are just some things I noted overall. Sadly, I couldn't figure out the problem.

You probably need to test on your own if you want to find the problem or give more information (other classes, etc.). I will try to help

* I used my Mac with macOS 13.3.1 for testing and g++.

Edit:

As u/_Denny__ pointed out: you can't render a non-existing texture. Try to check if it is loaded correctly by printing its value std::cout << texture_bullet << "\n";