Getting an unhandled exception

Hello I have been following along with this Handmade Hero game and I am at the end of Day 4 I an unable to run the program because of an this error "Exception thrown at 0x013B56B2 in win32_handmade.exe: 0xC0000005: Access violation writing location 0x0390A000.
Unhandled exception at 0x013B56B2 in win32_handmade.exe: 0xC000041D: An unhandled exception was encountered during a user callback."

There is also these in the autos:

Pitch 5696 int
+ Row 0x03ef5140 "" unsigned char *


I am at a complete loss at what to do, I have already asked two different sites and both times didn't get a single response so any help would be greatly appreciated.

The exception occurs right at the last line of this code sample

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include <windows.h>
#include <stdint.h>
#include "win32_handmade.h"

#define internal static 
#define local_persist static 
#define global_variable static

typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;

// TODO(casey): This is a global for now.
global_variable bool Running;

global_variable BITMAPINFO BitmapInfo;
global_variable void *BitmapMemory;
global_variable int BitmapWidth;
global_variable int BitmapHeight;
global_variable int BytesPerPixel = 4;

internal void
RenderWeirdGradient(int BlueOffset, int GreenOffset)
{
	int Width = BitmapWidth;
	int Height = BitmapHeight;

	int Pitch = Width * BytesPerPixel;
	uint8 *Row = (uint8 *)BitmapMemory;
	for (int Y = 0;
		Y < BitmapHeight;
		++Y)
	{
		uint32 *Pixel = (uint32 *)Row;
		for (int X = 0;
			X < BitmapWidth;
			++X)
		{
			uint8 Blue = (X + BlueOffset);
			uint8 Green = (Y + GreenOffset);

			*Pixel++ = ((Green << 8) | Blue);
		}

		Row += Pitch;
	}
}

where did row get its memory so that Row+= pitch works?
The answer is Row is Bitmapmemory, which is a global, which has not been assigned a valid value.

also make sure pitch is always correct, or it may shoot Row out of bounds.

it is unusual to just declare void pointers. Usually they are just a transport so you can pass an unknown 'thing' into a function that can then (somehow) un-thing it back into something concrete. For example, many thread libraries take a void * to the thread function's arguments, which can be anything, so its just a pass-through.

typedefs for the built in integer names is unhelpful as well, people now have to relearn YOUR version on top of microsoft's version on top of C++ and c99 and whatever else versions. There are probably 150 names for 4 things (1,2,4,8 byte ints) already!!!


Last edited on
I am not sure exactly, I have been copying his code word for word just as a way to get into coding.

His code worked on his video, while mine doesn't so I'm not really sure what to do differently.
Topic archived. No new replies allowed.