Sep 30, 2009

malloc fail

昨天生出了個BUG,主要的問題是ACCESS VIOLATION,現在還寫得出這種蠢程式真是讓我哭笑不得啊。

MARK說XP對記憶體的保護比較不嚴格,所以就算動到了不該動的位置也不見得會立刻出事。我碰到的情況是MALLOC忽然就失敗了,而整個程式吃掉的記憶體才13MB左右,因此斷定不是LOOP+LEAK,但是由於只是配置失敗,所以程式跑起來好像沒事一樣,只不過東西出不來而已。於是我開了些除錯用的例外,果然程式在出錯的地方丟出意外,仔細檢查後才發現是BUFFER SIZE算錯。

結論:MALLOC會失敗是因為動到HEAP記錄的地方(HEAP CORRUPTION)。

Sep 16, 2009

pack problem again


struct TGA_HEADER
{
unsigned char cbIDField;
unsigned char iColorMapType;
unsigned char iImageType;
//--1 byte padding

short ofsColorMap;
short cColorMap;
unsigned char cColorMapBits;
//--1 byte padding

short dX;
short dY;
short dWidth;
short dHeight;
unsigned char dColorDepth;
unsigned char descImage;
};

I have tried to make tga file yesterday and kept fail. When the image being dragged into directx texture tool, it alwayse told me something wrong in that file. But the header should be 18 bytes and the sum of all fields in the struct is 18 bytes, too. Finally, I started to check the pack issue as before. Then the problem emerged ! You can find a comment to mark the 1 byte padding in the code. To fix this only need 2 extra lines :

#include
struct TGA_HEADER
{....};
#include

Sep 4, 2009

Rome

Pantheon 萬神殿

Sep 1, 2009

粗糙的lit pre pass


大概知道 lit pre pass 是怎麼一回事了,然後很嗨的用了一堆super shape 想做個太空都市,結果根本是個廢墟……試了一些東西,大致上可行,點光源還是用球做的,這次加上geometry instancing,應該可以用告示板來代替。之前沒仔細看wolf的blog,結果用兩個角度來表示法向量,但是如果法向量是在view space 裡的話,就可以直接存xy,因為對鏡頭來說,所有可見點的法向量 z都是負的!

現在又有別的問題了(MSAA),但是我想寫個炫點的小程式啊!