• Advertisement

Getting 0xcccccccc error

Recommended Posts

I don't know why this is happening, in the image below you can see my current situation.

Basically I have an Utility.h header which contains wathever random stuff I think is useful at the time but don't yet deserves it's own separate file, so inside of it I've put a BaseFont class and defined it in place since I am not sure it will stay into Utility.h for long (Font is an alias for BaseFont because I wanted the internal variable name for the font to be Font, and that would collide with the class name, so that's why I have it setup like this) and right below this class, still in the header, I have a global object constructed from it so that I can use it everywhere for debug since pretty much all my .cpp #include "Utility.h". Now when I close the game I get an error that says "Breakout.exe stop working" and I tracked it down to the BaseFont destructor. On the right of the image you can see the local variable situation at that break point, which doesn't looks good...

I have some assumptions regarding the cause but I am not quite sure, can you tell me what its going wrong exactly? :P

FULL SIZE IMAGE

IbHWiGx.png

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
Advertisement
2 minutes ago, Hodgman said:

Your class doesn't comply with the rule of three, which means that if anyone copies it, you'll end up with a double deletion bug in the destructor, so that could be it.

Added the code below, still in the same situation, must be something else :)

	BaseFont(const BaseFont&) = delete;
	BaseFont& operator=(const BaseFont&) = delete;
	BaseFont(BaseFont&&) = delete;
	BaseFont& operator=(BaseFont&&) = delete;

 

Share this post


Link to post
Share on other sites

More informations:

App::~App()
{
	if (Window) { SDL_DestroyWindow(Window); }
	if (Renderer) { SDL_DestroyRenderer(Renderer); }
	for (auto& elem : Textures)
	{ SDL_DestroyTexture(elem.second); }

	if (TTF_WasInit()) { TTF_Quit(); };
	SDL_Quit();
}

I think the "global static" Font Arial lifetime has to do with the problem, since I am guessing the object is probably still around after TTF_Quit() is called (which happen after main() returns basically.

But still, I tested by removing the TTF_Quit() and it improves since I don't get the "Breakout.exe stop working" anymore, but according to the debbugger when we hit that breakpoint in the image in the first post, the situation is still the same, the memory of "this" being 0xcccccccc... any idea why is that? :/

Share this post


Link to post
Share on other sites
8 minutes ago, MarcusAseth said:

the memory of "this" being 0xcccccccc... any idea why is that?

0xcc is microsoft's debug mode marker for uninitialized stack memory. You'll notice others over time too -- 0xcd is uninitialized heap memory, 0xdd/0xfeee is free'ed memory, 0xfd is guard regions to check for overruns... So this is an indication that 'this' is pointing to a region of the stack that's never been used :o

What's the call-stack when the crash happens? How are you instantiating the BaseFont class?

[edit] Taking another look at your code, a side issue is that you never initialize the 'Font' member, but read from it before ever writing to it (via "if (Font)"). This is extremely dangerous and is only working due to luck at the moment.

Share this post


Link to post
Share on other sites

I apologize, actually it appears that if I step forward into the code, the 0xcccccccc turns itself into a reasonable address when it hit the problem (as shown in the image below), and the problem I think it was calling a TTF function after TTF_Quit().

It's just strange that didn't show me the proper "this" address at the breakpoint and even after stepping forward twice, only changed into it when it hits the error, is this something that happens debugging static variables?!

Anyway I still have the problem of  TTF_Quit() being called before the font are closed...how should I do in order to have that font global? I should like wrap it into a "global static FontManager" in which I register and request fonts and it takes care of freeying all the fonts before calling TTF_Quit()? Seems the only way I think :\

Ml7Ud0b.png

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

The Font is a static object created in an included header, the App object is created inside of main(), I think it has to do with it.

I placed 2 breakpoints, one on App destructor and one on the Font destructor, App's destructor get fired first :\

So that's why I thought they should be wrapped together in another class "FontManager", so that I can keep the global object behaviour for the Font and correctly order the cleanup inside of a single destructor

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Don't create code that runs before/after main. That means don't create global objects with non-trivial constructors/destructors. It only causes headaches.

If you really need a global font (hint: you don't, but whatever), then create the font object itself inside main, and create a global pointer to it.

Share this post


Link to post
Share on other sites
7 minutes ago, Hodgman said:

If you really need a global font (hint: you don't, but whatever)

Got it :D

I should probably pack it in a vector<Font> into the App class . Is ok to have it on the stack though? Or should I use unique_ptr for those as well? Font sounds like a lightweight thing, but I don't want to make assumptions...

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

you're problem is that you are declaring a global in a header file like that. What happens is that each cpp file that includes that utils header, gets its own copy of the static variable. You end up with many, and depending how you initialize them, destructor mayhem.


Simple Test:

//util.h
#pragma once
#include <iostream>
#include <string>

static int globali = 5;
  
//main.cpp
#include "utilglobals.h"
#include "cpp2.h"

void main() {

	testGlobal();
	std::cout << "main" << (int)&globali << std::endl;

	std::cin.get();
}
//cpp2.h
#pragma once
#include "utilglobals.h"
void testGlobal();
  
//cpp2.cpp
#include "cpp2.h"
void testGlobal() {
	std::cout << "cpp2" << (int)&globali << std::endl;
}

 

Share this post


Link to post
Share on other sites

if you want to do a global you'd use a singleton of some sort:

class Singleton {
	Singleton();

	static Singleton mInstance;
public:
	static Singleton* getInstance() {
		return &mInstance;
	}

	void func();
};
//in a cpp
Singleton Singleton::mInstance;	//only exists in 1 cpp file

Singleton::getInstance()->func();

 

Edited by h8CplusplusGuru

Share this post


Link to post
Share on other sites

@h8CplusplusGuru Thanks for letting me know, I though that pragma once would ensure only one copy of the thing (so now I have no idea about what pragma once is doing, and furthermore the usage of static keyword...

This is my output:

Quote

00092390 Constructor
00092448 Constructor
00092500 Constructor
000925B8 Constructor
00092670 Constructor
00092728 Constructor
000927E0 Constructor
00092898 Constructor
00092950 Constructor


00092950 Destructor
00092950 Font was 0030FC88
00092898 Destructor
00092898 Font was 0030A7C8
000927E0 Destructor
000927E0 Font was 00305308
00092728 Destructor
00092728 Font was 002FFE48
00092670 Destructor
00092670 Font was 002FA988
000925B8 Destructor
000925B8 Font was 002F54C8
00092500 Destructor
00092500 Font was 002F0008
00092448 Destructor
00092448 Font was 002C5D68
00092390 Destructor
00092390 Font was 002C0440

so basically I was creating and destroying 9 identical Font objects, very wasteful xD 

Share this post


Link to post
Share on other sites

Your header files are managed by each cpp, not the singular program. Pragma once means it's only included once per a cpp. Static is going to be redundant at a module scope, which is always program lifetime - at other scopes, it effectively makes them module in lifetime. Static is going to be used inside classes, inside functions.

On a somewhat related topic, you want to include as few headers in other headers as possible, and include them in cpps instead. You want to have as little code other than interfaces in headers as possible, because when the header changes, the cpp users compile. Both of these tips will increase your compile speeds. (Also, on msvc, enable, /MP, which is multiprocessor compilation ).

Share this post


Link to post
Share on other sites

Historically one used the following construct via macros

#ifndef MY_HEADER_HPP

#define MY_HEADER_HPP

// some DEFINITIONS (doesn't matter for DECLARATIONS only)

#endif

to ensure at most one "actual include" in each translation unit, otherwise you would have clashes. 

All C/C++ compilers support this (It is actually the preprocessor who support this).

The following construct

#pragma once

is supported by some compilers such as MVC++ and achieves the same result with the additional benefit of not polluting your namespace of globally defined symbols (which negatively influences your preprocessor's and probably "intelligent" IDE's performance due to some larger lookup tables) with one defined symbol for each header.

Edited by matt77hias

Share this post


Link to post
Share on other sites
On 28-9-2017 at 5:20 PM, MarcusAseth said:

static keyword

The static keyword has multiple use cases including imposing internal linkage. static struct/class member variables and methods, have, however, nothing to do with internal linkage. It basically adds data and functionality to the struct/class instead of the instances of that struct/class.

Edited by matt77hias

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By reenigne
      For those that don't know me. I am the individual who's two videos are listed here under setup for https://wiki.libsdl.org/Tutorials
      I also run grhmedia.com where I host the projects and code for the tutorials I have online.
      Recently, I received a notice from youtube they will be implementing their new policy in protecting video content as of which I won't be monetized till I meat there required number of viewers and views each month.

      Frankly, I'm pretty sick of youtube. I put up a video and someone else learns from it and puts up another video and because of the way youtube does their placement they end up with more views.
      Even guys that clearly post false information such as one individual who said GLEW 2.0 was broken because he didn't know how to compile it. He in short didn't know how to modify the script he used because he didn't understand make files and how the requirements of the compiler and library changes needed some different flags.

      At the end of the month when they implement this I will take down the content and host on my own server purely and it will be a paid system and or patreon. 

      I get my videos may be a bit dry, I generally figure people are there to learn how to do something and I rather not waste their time. 
      I used to also help people for free even those coming from the other videos. That won't be the case any more. I used to just take anyone emails and work with them my email is posted on the site.

      I don't expect to get the required number of subscribers in that time or increased views. Even if I did well it wouldn't take care of each reoccurring month.
      I figure this is simpler and I don't plan on putting some sort of exorbitant fee for a monthly subscription or the like.
      I was thinking on the lines of a few dollars 1,2, and 3 and the larger subscription gets you assistance with the content in the tutorials if needed that month.
      Maybe another fee if it is related but not directly in the content. 
      The fees would serve to cut down on the number of people who ask for help and maybe encourage some of the people to actually pay attention to what is said rather than do their own thing. That actually turns out to be 90% of the issues. I spent 6 hours helping one individual last week I must have asked him 20 times did you do exactly like I said in the video even pointed directly to the section. When he finally sent me a copy of the what he entered I knew then and there he had not. I circled it and I pointed out that wasn't what I said to do in the video. I didn't tell him what was wrong and how I knew that way he would go back and actually follow what it said to do. He then reported it worked. Yea, no kidding following directions works. But hey isn't alone and well its part of the learning process.

      So the point of this isn't to be a gripe session. I'm just looking for a bit of feed back. Do you think the fees are unreasonable?
      Should I keep the youtube channel and do just the fees with patreon or do you think locking the content to my site and require a subscription is an idea.

      I'm just looking at the fact it is unrealistic to think youtube/google will actually get stuff right or that youtube viewers will actually bother to start looking for more accurate videos. 
    • By mister345
      Hi, can someone please explain why this is giving an assertion EyePosition!=0 exception?
       
      _lightBufferVS->viewMatrix = DirectX::XMMatrixLookAtLH(XMLoadFloat3(&_lightBufferVS->position), XMLoadFloat3(&_lookAt), XMLoadFloat3(&up));
      It looks like DirectX doesnt want the 2nd parameter to be a zero vector in the assertion, but I passed in a zero vector with this exact same code in another program and it ran just fine. (Here is the version of the code that worked - note XMLoadFloat3(&m_lookAt) parameter value is (0,0,0) at runtime - I debugged it - but it throws no exceptions.
          m_viewMatrix = DirectX::XMMatrixLookAtLH(XMLoadFloat3(&m_position), XMLoadFloat3(&m_lookAt), XMLoadFloat3(&up)); Here is the repo for the broken code (See LightClass) https://github.com/mister51213/DirectX11Engine/blob/master/DirectX11Engine/LightClass.cpp
      and here is the repo with the alternative version of the code that is working with a value of (0,0,0) for the second parameter.
      https://github.com/mister51213/DX11Port_SoftShadows/blob/master/Engine/lightclass.cpp
    • By Rannion
      Hi, I am sending data to peers and those data need to be retreived from a scenegraph with a mutex to lock the data.
      The process of gathering the data is taking a bit less than a ms. I'm starting the thread every time I want to gather the data. If I'm running at 60 fps, I'm starting the thread 60 times per second so is that a performance or design problem?
      Would it be much better to have the thread always running and some kind of mechanism to ask him to perform the task whenever it's needed, so around 60 or 120fps?
      Also, does starting a thread creates some memory alloc/dealloc and then produce on the long run some kind of fragmentation?
      Thank you all.
    • By stream775
      Hello!
                I wrote a simple bones system that renders a 3D model with bones using software vertex processing. The model is loaded perfectly, but I can't see any colors on it. For illustration, you can see the 3D lines list, the bones ( 32 bones ) are in correct position ( bind pose ).
       
      Now, here's the problem. When I try to render the mesh with transformations applied then I see this:
      As you can see the 3D lines are disappearing, I'm guessing the model is rendered, but the colors are not visible for whatever reason. I tried moving my camera around the line list, but all I can see is some lines disappearing due to the black color of vertices? I'm not loading any textures, am I suppose to load them?
      However, if I render the vertices without applying ANY bone transformations, then I can see it, but it's a mess, obviously. If you're wondering why it's red, I have set color of these vertices ( only half of them ) to red and the rest half is white.
      First of all, my apologies for the messy code, but here it is:
      I'm not sure if vertices are suppose to have weights in them for software vertex processing. I'm storing them in a container, so you don't see them here.
      #define CUSTOMFVF ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE ) struct CUSTOMVERTEX { D3DXVECTOR3 Position; D3DXVECTOR3 Normal; DWORD Color; }; This is how I store the vertices in container and give them red and white color:
      This is how I create the device:
      For every frame:
      This is the UpdateSkinnedMesh method:
      I have debugged bone weights and bone indices. They are okay. Bone weights add up to 1.0f, so I'm really wondering why I can't see the model with colors on it?
    • By komires
      We are pleased to announce the release of Matali Physics 4.0, the fourth major version of Matali Physics engine.
      What is Matali Physics?
      Matali Physics is an advanced, multi-platform, high-performance 3d physics engine intended for games, virtual reality and physics-based simulations. Matali Physics and add-ons form physics environment which provides complex physical simulation and physics-based modeling of objects both real and imagined. The engine is available across multiple platforms:
              Android         *BSD         iOS         Linux         OS X         SteamOS         Windows 10 UAP/UWP         Windows 7/8/8.1/10         Windows XP/Vista What's new in version 4.0?
               One extended edition of Matali Physics engine          Support for Android 8.0 Oreo, iOS 11.x and macOS High Sierra (version 10.13.x) as well as support for the latest IDEs          Matali Render 3.0 add-on with physically-based rendering (PBR), screen space ambient occlusion (SSAO) and support for Vulkan API          Matali Games add-on  
      Main benefits of using Matali Physics:
              Stable, high-performance solution supplied together with the rich set of add-ons for all major mobile and desktop platforms (both 32 and 64 bit)         Advanced samples ready to use in your own games         New features on request         Dedicated technical support         Regular updates and fixes
      The engine history in a nutshell
      Matali Physics was built in 2009 as a dedicated solution for XNA. The first complete version of the engine was released in November 2010, and it was further developed to July 2014 forming multi-platform, fully manage solution for .NET and Mono. In the meantime, from October 2013 to July 2014, was introduced simultaneous support for C++. A significant change occurred in July 2014 together with the release of version 3.0. Managed version of the engine has been abandoned, and the engine was released solely with a new native core written entirely in modern C++. Currently the engine is intensively developed as an advanced, cross-platform, high-performance 3d physics solution.
       
      If you have questions related to the latest update or use of Matali Physics engine as a stable physics solution in your projects, please don't hesitate to contact us.

      View full story
  • Advertisement