Project1.exe Has Stopped Working. I cant seem to find what the heel is wrong with my SDL Code - c++

All right, i apologize right away because the code is actually kind of big. The thing is, i am working with SDL, learning actually. I had managed to create animations, but i decided i wanted to go a little deeper. This is how the Code works
App - Uses: This has the main loop, the Init function, the Render Function and the whole softwares is originated from here.
Animation - Uses: This will contain and declare all of the functions in the Class Animation. It only works when a bool variable called Running is true.
Surface - Uses: This will Load files onto surfaces, Make certain color transparents and Draw images or part of images onto the MainSurface.
Events - Uses: This has all of the Virtual Functions to Events
Object - Uses: This is the big part. It was working perfectly. Before i would have a Surface Called Yoshi on the Main Class, and i would interact with the animation using that Surface. I thought that the method of having the "Character" on the main Class was a little bit confusing and it would cause me problems when having Multiple images on the screen. So therefore i decided to create a class called Object, which would have its own SDL_Surface, its own location on screen, Its own variable decided which frame it is. What i did was that i created an object to This class on the APP Class... Something like
Object MainCharacter;
So then i would be able to manipulate that Character alone, and if i ever needed to have another Object on screen i would just use
Object *SecondCharacter;
etc... So then the OBJECT Class would call the Animation. APP Class would render all of the images, by a function somewhat like this
MySurface::OnDraw(Surf_Display, MainCharacter.Img_Surface, MainCharacter.RetrievePosX(), MainCharacter.RetrievePosY(), MainCharacter.RetrieveFrameByID(0), MainCharacter.RetrieveFrameByID(1), 64, 64);
Well... But the thing is: The code stops working. This is far from a finished code, but i would like to fix this issue right away, so i can finish only after it already has a base.
Here are all of the files: Some of them dont have too many lines. I also wrote some comments to help anyone who may be able to help me.
HEADERS:
Animation.h - http://pastebin.com/v4REcmBd
Object.h - http://pastebin.com/KdeamZTG
Events.h - http://pastebin.com/dpQ7zwpG
CApp.h - http://pastebin.com/5zZYwDjv
Surface.h - http://pastebin.com/S66ChQ3f
SOURCES:
Surface.cpp - http://pastebin.com/KRgAkHpw
Object.cpp - http://pastebin.com/RtDRwVj4
Events.cpp - http://pastebin.com/dpXn8Rh3
OnRender.cpp - http://pastebin.com/AqgMTacb
OnLoop.cpp - http://pastebin.com/UAeAt7y6
OnInit.cpp - http://pastebin.com/1iiZVeyK
OnEvent.cpp - http://pastebin.com/AjRXnKC1
OnCleanUp.cpp - http://pastebin.com/cv0M11nV
CApp.cpp - http://pastebin.com/L0jhfWY8
Animation.cpp - http://pastebin.com/0BZhh6TG
All right those are it. Some of them are really short. Well, if anyone can help me finding where is my mistake i would be glad. And with that aside, i would really like to get an opinion on the structure of the software, do you think what i am doing is practical? What Design do YOU use when creating SDL Software or Games???

Having been told in the comments it happens on line 12 of Source.cpp which says
Res = SDL_DisplayFormat(Temp);
and googled SDL_DisplayFormat for you, I find this manual page
Near the bottom it says:
Newbie hint
You have to call SDL_Init before using the SDL_DisplayFormat function.
If you don't, your program will crash with an access violation.

Related

Initialization of wxColourDataBase while creating a new wxColourPickerCtrl

This is my first question ever posted, so please let me know if there is anything that needs changes in my post :)
I am currently working on a dialog that is supposed to let the user change the background-color for some signal plotting. The "wxColourPickerCtrl" seems to do exactly what I need. Since there are multiple plots/pictures to be manipulated, the ColourPickerCtrls are initialized in a loop with the chosen background color as the default value:
for (const auto& [signalName, signalProperties] : properties)
{
wxColourPickerCtrl* selectBackgroundColor = new wxColourPickerCtrl(this, signalProperties.first, signalProperties.second.backgroundColor, wxDefaultPosition, wxDefaultSize);
}
"this" is an object of type SignalPropertiesDialog, which is directly inherited from wxDialog.
I have left out all the necessary sizer stuff, since it's not relevant for the problem (at least imo). "properties" is structured as follows:
std::map<std::string, std::pair<int, GraphPicture::Properties>> signalProperties_;
where GraphPicture::Properties contains the properties I want to manipulate:
struct Properties
{
wxColour backgroundColor{ *wxWHITE };
wxColour lineColor{ *wxBLACK };
int linewidth_px{ 1 };
bool isShown{ true };
};
The application successfully builds but immediately crashes on startup while generating those color picker objects.
wxIshiko has uploaded multiple tutorials and code snippets as examples for various wxWidgets controls, including the wxColourPickerCtrl. So I downloaded the sample code and tried to run it. Surprisingly, it worked.
While running through the code step by step I noticed the following difference:
The wxColourPickerCtrl is based on wxPickerBase. The wxPickerBase is created by calling the constructor of wxColourPickerCtrl (what I am actually doing in my code). During the construction of the wxPickerBase, the desired color is called by the name wxColourDataBase::FindName(const wxColour& color) const where the wxColourBase itself is instantiated. This is where the difference is:
When running the code snippet by wxIshiko, wxColourDataBase is instantiated correctly including the member m_map of type wxStringToColourHashMap* which is set to be NULL.
When running the code written by myself, wxColourDataBase is not correctly instantiated, and thus the member m_map is not set to be NULL, which leads to to the crash.
I have the feeling that there is nothing wrong with the way I set up the wxColourPickerCtrls. I somehow think there is a difference in the solution properties of the projects. I checked those but was not able to find any relevant differences.
I would really appreciate any hint or help since I am completely stuck on that problem.
Thank you very much in advance and have a good one,
Alex
EDIT:
I attached a screeny of the call stack.
Call stack
When does this code run exactly? If it is done after the library initialization (which would be the case, for example, for any code executed in your overridden wxApp::OnInit()), then wxTheColourDatabase really should be already initialized and what you observe should be impossible, i.e. if it happens it means that something is seriously wrong with your library build (e.g. it doesn't match the compiler options used when compiling your applications).
As always with such "impossible" bugs, starting with a known working code and doing bisection by copying parts of your code into the working version until it stops working will usually end up by finding a bug in your code.

glBindTexture - returns argument error

I am working on augmented reality project. So the user should use the Webcam, and to see the captured video with a cube drawn on that frame.
And this is where I get stuck , when I try to use glBindTexture(GL_TEXTURE_2D,texture_background) method, I get error:
(
ArgumentError: argument 2: : wrong type
GLUT Display callback with (),{} failed: returning None argument 2: : wrong type
)
I am completely stuck, have no idea what to do . The project is done in Python 2.7 , am using opencv and PyOpenGl 3.1.0.
You can find code on this link :click here
Thanks in advance.
Interesting error! So I played around with your source code (by the way in the future you should probably just add the code directly to your question instead of as a separate link), and the issue is actually just one of variable scope, not glut or opengl usage. The problem is your texture_background variable does not exist within the scope of the _draw_scene() function. To verify this, simply try calling print texture_background in your _draw_scene() function and you will find it returns None rather than the desired integer texture identifier.
The simple hack-y solution is to just call global texture_background before using it within your _handle_input() function. You will also need to define texture_background = None in the main scope of your program (underneath your ##FOR CUBE FROM OPENGL comment). The same global comment applies for x_axis and z_axis.
That being said, that solution is not really that great. The rigid structure required by GLUT with all of these predefined glut* functions makes it hard to structure code the way you might want to in terms of initializing your app. I would suggest, if you are not forced to use GLUT, to use a more flexible alternative, such as pygame, pysdl2 or pyqt, to create your context instead.

XTK - rendering volume in multiple renderers without .onShowtime()?

I'm wondering if someone can explain to me why I can't render the same volume in a 4 panel setup (3D, X, Y, Z) just like in XTK Tutorial 13, without the .onShowtime function. I tried altering the code to do this, rather than call the .onShowtimes function:
volume = new X.volume();
volume.file = 'http://x.babymri.org/?vol.nrrd';
sliceX.add(volume);
sliceX.render();
sliceY.add(volume);
sliceY.render();
sliceZ.add(volume);
sliceZ.render();
but when I do this, I get the load bars in the 3 display panels, but after loading, only the sliceX panel will display an image, the others remain black. Do I always have to have a main renderer and make the other renderers listen to it, as the tutorial suggests?
Thanks,
Dave
It is because the first call to 'render' is going to trigger the downloading of the data.
Once it has been downloaded 1 time and rendered the first time, we add/render it in the other renderers.
When we call 'render' on the next renderers, it will not try to download the data again since it has already been downloaded once.
If we call renderer as you are doing it right now, it tries to download the volume 3 times and it can mess up the internals of the object.
So long answer short, it is to avoid some race conditions but I agree we should improve that if possible.
Thanks
I have solved it temporaly replacing onShowTime with the JavaScript function setTimeout.You render the first renderer and after that you rend the others inside that function
volume = new X.volume();
volume.file = 'http://x.babymri.org/?vol.nrrd';
slice3D.add(volume);
slice3D.render();
setTimeout(function(){
sliceX.add(volume);
sliceX.render();
sliceY.add(volume);
sliceY.render();
sliceZ.add(volume);
sliceZ.render();
},600);
it worked for me.

Migrating to vtk6: Is it not necessary to Update() (anymore)?

Migrating some code from VTK 5.10 to 6.1, I have several code pieces like this:
vtkSmartPointer<vtkImageData> img = vtkSmartPointer<vtkImageData>::New();
// ... initialize img somehow, e.g. copy from other image:
img->DeepCopy(otherImg);
img->SetInformation(otherImg->getInformation());
// the problematical statement:
img->Update();
At the call to Update(), the compiler now complains that there isn't such a function (anymore).
The migration site from VTK doesn't really tell me too much about that - I believe this falls into the section Removal of Data Objects’ Dependency on the Pipeline , but as it's no Algorithm which is filling my image, I can't call update on an algorithm.
Similar goes for custom-filled vtkPolyData objects.
My question now is: Is the call to Update not necessary (anymore?), can I just remove it? Or by what would I need to replace it?
I have to say I'm relatively new to vtk, so if there's something fundamentally simple that I'm missing I'd be glad if you could point it out to me!
I think you've been meaning to call Modified() on your image rather than Update().
Apparently they already answered your question on VTK:
http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Removal_of_Update

How do you control a player character in Bullet Physics?

I am not sure how you are supposed to control a player character in Bullet. The methods that I read were to use the provided btKinematicCharacterController. I also saw methods that use btDynamicCharacterController from the demos. However, in the manual it is stated that kinematic controller has several outstanding issues. Is this still the preferred path? If so, are there any tutorials or documentations for this? All I found are snippets of code from the demo, and the usage of controllers with Ogre, which I do not use.
If this is not the path that should be tread, then someone point me to the correct solution. I am new to bullet and would like a straightforward, easy solution. What I currently have is hacked together bits of a btKinematicCharacterController.
This is the code I used to set up the controller:
playerShape = new btCapsuleShape(0.25, 1);
ghostObject= new btPairCachingGhostObject();
ghostObject->setWorldTransform(btTransform(btQuaternion(0,0,0,1),btVector3(0,20,0)));
physics.getWorld()->getPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
ghostObject->setCollisionShape(playerShape);
ghostObject->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
controller = new btKinematicCharacterController(ghostObject,playerShape,0.5);
physics.getWorld()->addCollisionObject(ghostObject,btBroadphaseProxy::CharacterFilter, btBroadphaseProxy::StaticFilter|btBroadphaseProxy::DefaultFilter);
physics.getWorld()->addAction(controller);
This is the code I use to access the controller's position:
trans = controller->getGhostObject()->getWorldTransform();
camPosition.z = trans.getOrigin().z();
camPosition.y = trans.getOrigin().y()+0.5;
camPosition.x = trans.getOrigin().x();
The way I control it is through setWalkDirection() and jump() (if canJump() is true).
The issue right now is that the character spazzes out a little, then drops through the static floor. Clearly this is not intended. Is this due to the lack of a rigid body? How does one integrate that?
Actually, now it just falls as it should, but then slowly sinks through the floor.
I have moved this line to be right after the dynamic world is created
physics.getWorld()->getPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
It is now this:
broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(new btGhostPairCallback());
I am also using a .bullet file imported from blender, if that is relevant.
The issue was with the bullet file, which has since been fixed(the collision boxes weren't working). However, I still experience jitteryness, unable to step up occasionally, instant step down from to high a height, and other issues.
My answer to this question here tells you what worked well for me and apparently also for the person who asked.
Avoid ground collision with Bullet
The character controller implementations in bullet are very "basic" unfortunately.
To get good character controller, you'll need to invest this much.