Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:28:08+00:00 2026-06-14T16:28:08+00:00

I’m making a game in SDL, and I’m using SDL_VideoInfo to get the monitors

  • 0

I’m making a game in SDL, and I’m using SDL_VideoInfo to get the monitors current resolution.

Example Code: (This may have a few spelling mistakes or wrong names for functions/variable types, i’m writing this right now off my memory).

#include <SDL.h>
#include <iostream>
using namespace std;

int main()
{
    SDL_Init(SDL_INIT_EVERYTHING);
    const SDL_VideoInfo *vInfo = SDL_GetVideoInfo();
    cout << "Moniter Resolution:\n";
    cout << vInfo->current_w << endl << vInfo->current_h << endl;
    delete vInfo;
    return 0;        
}

The first few times I run this, it works fine, then I get the Debug Assertion Failed window popping up on me. I’m not quite sure what it means, but I think it has to do with memory leaks? I’m coming from Java here, so memory leaks and pointers and such is all new to me, so
i’m kinda confused.

Anyway, the code works fine when I dont delete vInfo, but after all the C++ books and videos I’ve looked at, they all send the message that not deleting your pointers is programming sacrilege. So, (apparently) deleting vInfo is my only choice.

So, I think, think I fixed it by doing this, or, at least when I do this there are not Debug Assertion Failed messages: (Once again, doing this from memory, I might have some spelling mistakes or typos that would cause an error, but you should get the point).

int main()
{
    SDL_Init(SDL_INIT_EVERYTHING);
    auto_ptr<const SDL_VideoInfo> vInfo(SDL_GetVideoInfo());
    cout << "Moniter Resolution:\n";
    cout << vInfo->current_w << endl << vInfo->current_h << endl;
    vInfo.release();
    return 0;        
}

Throw it in an auto pointer, and It all works out. Although I’m still not sure if this is fixing the problem; just because I’m not getting an error message doesn’t mean that something bad isn’t happening.

My question is, why do I have to put vInfo in an auto_ptr to avoid this error, is there a way that I can do this without using an auto_ptr, or do I even have to worry about deleting vInfo at all?

Some people might say that this question is useless as I have fixed the problem, but the question i’m asking is not how to fix this error, it is why I got the problem in the first place, and if my solution can be revised in any way(not having to use an auto_ptr, or not having to delete vInfo at all).

P.S. This error certainly isn’t just my computer doing something wierd, I’ve run the same code on multiple computers and got the same result.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:28:10+00:00Added an answer on June 14, 2026 at 4:28 pm

    From the documentation:

    [SDL_GetVideoInfo()] Returns a read-only pointer to the structure containing the information about the current video hardware.

    SDL is managing the pointed-to memory so don’t try to delete it. In all likelihood it’s returning a pointer to a static structure.

    Though even if SDL (a C library) wasn’t managing the memory and expected you to clean it up you should never call delete on malloc()‘d memory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.