Page 1 of 1

Beginning C++ Tutorial 14

Posted: June 25th, 2019, 1:00 am
by DrewAmu
Stuck in Chili Tutorial 14a -please advise me what may be causing this problem: I got to the point in the tutorial where I'm "testing the grid" right before coding the Snake class; I downloaded the Tutorial 14 Framework and added the code exactly as shown in the Tutorial; The program crashes - actually it terminates itself after flashing a white screen. I don't get an "Assertion Failed" error. In Debug mode I get an "Un-handled Exception" at the line which starts with pSysBuffer in the PutPixel function in the Graphics.cpp file. I'm using Visual Studio 2017, Windows 10 - 64 bit and have not had this problem doing all the previous Tutorials. I would appreciate suggestions.

Re: Beginning C++ Tutorial 14

Posted: June 25th, 2019, 2:55 am
by WilsonHuang
Hi, DrewAmu, please check the Solution Configuration is switched to "Debug".
If the solution configuration is release mode. The assertion check will be skipped

UPDATED:
Be sure your value of x in PutPixel is between 0 and 799, y is between 0 to 599
未命名.png
(67.98 KiB) Not downloaded yet

Re: Beginning C++ Tutorial 14

Posted: June 27th, 2019, 9:20 pm
by DrewAmu
The issue seems to be that in the ComposeFrame function the Color object "c" is initialized with the r, g, and b values which are between 0 - 255, then when it jumps to the DrawCell function "c" contains (apparently) meaningless integer values with many digits. I am assuming that these values are causing the Exception to be thrown when they are passed to the PutPixel function. I don't really understand how the Color class overloaded constructors work but I think that may be where the values are getting corrupted.

Re: Beginning C++ Tutorial 14

Posted: June 28th, 2019, 3:09 am
by albinopapa
Not likely unless you changed something. If you can't figure it out after doing some debugging, either upload a compressed copy of your solution and subfolders or share the github address to your repository and we'll try to steer you in the right direction.

Re: Beginning C++ Tutorial 14

Posted: July 4th, 2019, 1:33 am
by DrewAmu
After carefully following the values while stepping slowly through the program, I realized that what I guessed in the above reply was wrong. The values were all as expected right up until I got this message: Exception thrown read access violation; This was nullptr.
Here is what solved the problem: Instead of the "cache" method that Chili used to store the Graphics reference in Board class, I passed the Graphics reference in the DrawCell function along with the Location and Color references, and removed the Graphics constructor from Board. I don't understand why this worked, since the two ways of referencing Graphics should be equivalent. I also don't understand why the cache method didn't work for me since I haven't heard of anyone else having this problem. I'm uploading the source files (entire Engine folder) in case anyone would like to try to figure this out.

Re: Beginning C++ Tutorial 14

Posted: July 5th, 2019, 3:18 am
by albinopapa

Code: Select all

Game::Game( MainWindow& wnd )
	:
	wnd( wnd ),
	gfx( wnd ),
	brd(brd), 
	rng(std::random_device()())
{
}
There is an error here.

Re: Beginning C++ Tutorial 14

Posted: July 5th, 2019, 5:48 pm
by DrewAmu
Thank you! I knew there had to be some dumbass error somewhere, but I just couldn't see it. Even though I was able to get the program to run it bothered me that it wouldn't work the way it was supposed to. I feel better now.

Re: Beginning C++ Tutorial 14

Posted: July 6th, 2019, 3:53 am
by albinopapa
Awesome.

Re: Beginning C++ Tutorial 14

Posted: July 9th, 2019, 8:42 pm
by ariston
Hey guys, for some reason when I'm trying to run the code with the board class, just before adding the snake class, my grid only shows blue color.
My random generator works because the blue shade changes value, however the red and green do nothing.
I tried changing them manually but still nothing

Re: Beginning C++ Tutorial 14

Posted: July 9th, 2019, 10:08 pm
by albinopapa
What have you changed, the version you posted after fixing showed random colors and not just blue.