| FlyingMonkey456 (41) | |||
I'm writing a simple class for rendering 2D graphics. The relevant code in the initialization for the class is:
When I try to run it, I get a memory access error on this line: _displaylist[_dlistsize] = graphic;I've checked the value of _dlistsize and it is still 0 when the line runs. I get no errors until I run it. | |||
|
Last edited on
|
|||
| ResidentBiscuit (2651) | |
| What's exact error? | |
|
|
|
| FlyingMonkey456 (41) | |
|
The error is: Unhandled exception at x00cccb6e in Project.exe: 0xC0000005: Access violation writing location 0x00000000. | |
|
|
|
| jlb (170) | |||
You need to show more code, but since this is a C++ program the following is not allowed:
When declaring arrays the size must be a compile time constant. | |||
|
|
|||
| Krzysztof Kawa (3) | |
|
The problem is probably somewhere else, but you've got weird usage of ZeroMemory. The & is irrelevant in this case, and because ZeroMemory operates on bytes(size 1) I think this should be something like: ZeroMemory(_displaylist, _dlistmax * sizeof(/*whatever the type of items in _displaylist is*/));
| |
|
|
|
| FlyingMonkey456 (41) | |
|
I've changed _dlistmax to a constant, but I have no idea how to initialize it now. Also, Krzysztof, ZeroMemory was giving me an error before, so I put the & there and it fixed it. I just thought about it though and changed it to _displaylist[0]. | |
|
|
|
| jlb (170) | ||
What to initialize a constant you assign a value when you declare the const: const int my_value = 100;
| ||
|
|
||
| FlyingMonkey456 (41) | |
I just tried to run it again and ZeroMemory is giving me the same error now. I changed it from &_displaylist to _displaylist[0].ZeroMemory(_displaylist[0], _dlistmax);
| |
|
|
|
| jlb (170) | |
Have you tried ZeroMemory(_displaylist, _dlistmax);, notice the lack of the ampersand?
| |
|
|
|
| FlyingMonkey456 (41) | |
| Yes, that just gives me an access violation error in memset.asm. | |
|
|
|
| FlyingMonkey456 (41) | |
Most likely, there's some problem accessing _displaylist. Would making it an array of pointers cause problems, by any chance? The declaration for it is: Graphic** _displaylist;I want to be able to move things around quickly in the array by just changing what the pointers point to. Have I broken something by doing that? | |
|
|
|
| Mathhead200 (951) | ||
It sounds like _displaylist has not been initialized. Check if _displaylist == 0Either that, or maybe _displaylist[0] == 0 | ||
|
Last edited on
|
||
| FlyingMonkey456 (41) | |
| _displaylist does not equal 0. _displaylist[0] gives me an access violation. | |
|
|
|
| ResidentBiscuit (2651) | ||
This usually means it hasn't been initialized. What type is _displaylist? | ||
|
|
||
| ne555 (4385) | |
> When declaring arrays the size must be a compile time constant._displaylist[_dlistmax]; is not a declaration... (probably that statement has no effect)
| |
|
|
|
| cire (2354) | ||
Indeed, you said it gives you Access violation writing location 0x00000000, which suggests that it is equal to zero. So, how are you making sure that it is not? | ||
|
|
||
| FlyingMonkey456 (41) | |||
|
Here's the code. I put it in the constructor after the initialization of the array. I commented out ZeroMemory because it was just causing problems. EDIT: I changed ZeroMemory back to what it was originally (with the ampersand) and _displaylist did equal zero.
| |||
|
Last edited on
|
|||
| ResidentBiscuit (2651) | ||
This does nothing. I'm surprised you don't get an error. This is equivalent to: arr[10];Doesn't declare, initialize, or assign anything. | ||
|
|
||
| FlyingMonkey456 (41) | |
| So could you tell me what to do instead? | |
|
|
|
| ResidentBiscuit (2651) | |
Are you trying to declare the array?type _displaylist[_dlistmax]; //Assuming _dlistmax is compile time constant
| |
|
|
|