Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

Weird access violation when copying data

This topic is 1062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 

  I'm trying to resize a bitmap for my 2d engine, however I keep getting an access violation at random points while I'm iterating through the bitmap. I really don't know what can be causing it. It comes up at random row/column and offset, can someone just look over my code and see what's wrong? 

 

void ResizeBitmap(BITMAP_FILE* out, BITMAP_FILE* original, RECT resizeRectangle){//only works for 32 bit bitmaps for nowif (original->infoHeader.biBitCount != 32)return;int newXDimension = resizeRectangle.right - resizeRectangle.left;int newYDimension = resizeRectangle.bottom - resizeRectangle.top;int newDataSize = (original->infoHeader.biBitCount / 8) * newXDimension * newYDimension;//layout of bmp//file header//dib header (info header)//data//first create a new file header//everything is the same as the old bitmap except the file sizeBITMAPFILEHEADER newFH = original->fileHeader;newFH.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + newFH.bfOffBits + newDataSize;//create a new info headerBITMAPINFOHEADER newIH = original->infoHeader;newIH.biHeight = newYDimension;newIH.biWidth = newXDimension;newIH.biSizeImage = newDataSize;//allocate the data (this is only for 32 bit bitmap)DWORD* newData = (DWORD*) new DWORD[newXDimension * newYDimension];//calculate the resize ratio in x dimensionfloat ratioX = float(newXDimension) / original->infoHeader.biWidth;float ratioY = float(newYDimension) / original->infoHeader.biHeight;DWORD* newDataOffset = newData;DWORD* origDataOffset = (DWORD*) original->data;//iterate throught the original bitmap and write to the new onefor (int row = 0; row < original->infoHeader.biHeight; row++){for (int column = 0; column < original->infoHeader.biWidth; column++){int destinationPixel = int(ratioX * column - 0.5f);newDataOffset[destinationPixel] = origDataOffset[column];}newDataOffset += newXDimension;origDataOffset += original->infoHeader.biWidth;}//copy everything back to the output bitmapout->fileHeader = newFH;out->infoHeader = newIH;out->data = (unsigned char*) newData;}

sorry what's the right code tag, this one didn't indent for some reason?

Edited by Brother Bob

Share this post


Link to post
Share on other sites
Advertisement

@Bacterius why isn't there a delete button for the posts? It was an obvious solution that I skimmed over (writing past array), so it wouldn't have helped anyone.

Edited by VanillaSnake

Share this post


Link to post
Share on other sites

It is a conscious decision of the forum not to have a delete button for threads. Even though you may feel there is little value sometimes it does sometimes help people. You would also be surprised at the number of people who ask a real question, get an answer and then try to remove their question and/or the whole thread. That goes very much against the spirit of a community like this and invalidates all use others have from it.

Nevertheless, if you truly feel a thread should be deleted you are free to petition the moderators to do so.

I would also like to point out that it is not a good idea to just lash out at people with the rating button. Bacterius was not the person who downvoted your post, he was just kind enough to post his reasons why you did get a minor slap on the wrist from someone else.

 

well if it's a conscious decision then this is a consequence of it. My post was a long wall of code that I couldn't get formated right and at the end it was a silly mistake. So I decided to delete it. i downvoted him because it's not his place to tell me not to delete my own post when he didn't even read it to begin with. 

Share this post


Link to post
Share on other sites

I actually did read what you posted, there is a "history" button you can use to see... but whatever, keep making assumptions. I'm exiting this thread now.

Share this post


Link to post
Share on other sites

I actually did read what you posted, there is a "history" button you can use to see... but whatever, keep making assumptions. I'm exiting this thread now.

oh good, then you can see why I deleted it, how many people you'd think it'd help?

Share this post


Link to post
Share on other sites
Deleting threads is bad netiquette. Do kids still say that? Netiquette?
Anyway, avoid doing it. Mods will just restore the deleted post from history and in the meantime everyone will rage at the bad netiquette, and then you'll raise your hackles and everyone will have a bad time. Speaking of time, it's time to lock this shitstorm away.

Share this post


Link to post
Share on other sites

This topic is 1062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!