TMX Tilemap Access Violation Exception

0

I am trying to load a simple TMX Tiled Map that I made using Tiled application into Visual Studio. But I am getting this error:

????????????
????????
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\StorageProxy.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Phone.Storage.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\PhotosAPI.dll'. Cannot find or open the PDB file.
'TaskHost.exe' (Win32): Loaded 'C:\Windows\System32\PhotosServiceClient.dll'. Cannot find or open the PDB file.
First-chance exception at 0x676D0BFB (libcocos2d_v3.3_WindowsPhone_8.0.dll) in TaskHost.exe: 0xC0000005: Access violation reading location 0x00000178.
Unhandled exception at 0x676D0BFB (libcocos2d_v3.3_WindowsPhone_8.0.dll) in TaskHost.exe: 0xC0000005: Access violation reading location 0x00000178.

The program '[4760] TaskHost.exe' has exited with code 0 (0x0).

So I did a bit of digging and found out that this was a bug when your resources are not in the same directory as the TMX file and was a bug which was eventually fixed as per this link

http://discuss.cocos2d-x.org/t/cocos2d-x-v3-tilemap-image-source-path/8315

I am using Cocos 2d-x V3.3

Here is the code that I am using in my init() function of my MainScene

bool MainScene::init()
{
    if (!Layer::init())
    {
        return false;
    }
...

auto tmxMap = TMXTiledMap::create("TMX/test-tiled-map.tmx");
    this->addChild(tmxMap);

...

    return true;
}

Also my tile resources belong to the same place as my .tmx file. i.e. the Assets/Resources/TMX/ Folder

Here is my .tmx File:

    <?xml version="1.0" encoding="UTF-8"?>
    <map version="1.0" orientation="orthogonal" renderorder="right-down" width="41" height="41" tilewidth="35" tileheight="35" nextobjectid="1">
     <tileset firstgid="1" name="OriginMap" tilewidth="35" tileheight="35">
  <tile id="0">
   <image width="35" height="35" source="water.png"/>
  </tile>
  <tile id="1">
   <image width="35" height="35" source="water-bot.png"/>
  </tile>
  <tile id="2">
   <image width="35" height="35" source="water-bot-left.png"/>
  </tile>
  <tile id="3">
   <image width="35" height="35" source="water-bot-right.png"/>
  </tile>
  <tile id="4">
   <image width="35" height="35" source="water-left.png"/>
  </tile>
  <tile id="5">
   <image width="35" height="35" source="water-right.png"/>
  </tile>
  <tile id="6">
   <image width="35" height="35" source="water-top.png"/>
  </tile>
  <tile id="7">
   <image width="35" height="35" source="water-top-left.png"/>
  </tile>
  <tile id="8">
   <image width="35" height="35" source="water-top-right.png"/>
  </tile>
 </tileset>
     <layer name="Tile Layer 1" width="41" height="41">
      <data>
       <tile gid="1"/>
       <tile gid="1"/>
       <tile gid="1"/>
       <tile gid="1"/>
       <tile gid="1"/>
    ... (lots of tiles of water) ...
       <tile gid="1"/>
       <tile gid="1"/>
      </data>
     </layer>
    </map>

Generated Call Stack by Visual Studio:

>   libcocos2d_v3.3_WindowsPhone_8.0.dll!cocos2d::Node::addChild(cocos2d::Node * child=0x00000000) Line 1065    C++
    EmpiresAtWarComponent.dll!MainScene::init() Line 94 C++
    EmpiresAtWarComponent.dll!MainScene::create() Line 18   C++
    EmpiresAtWarComponent.dll!MainScene::createScene() Line 9   C++
    EmpiresAtWarComponent.dll!AppDelegate::applicationDidFinishLaunching() Line 41  C++
    libcocos2d_v3.3_WindowsPhone_8.0.dll!cocos2d::Application::run() Line 77    C++
    EmpiresAtWarComponent.dll!Cocos2dRenderer::[DirectXBase]::CreateGLResources() Line 63   C++
    EmpiresAtWarComponent.dll!DirectXBase::UpdateDevice(ID3D11Device1 * device=0x005c7744, ID3D11DeviceContext1 * context=0x005c8820, ID3D11RenderTargetView * renderTargetView=0x03112a38) Line 110    C++
    EmpiresAtWarComponent.dll!cocos2d::Direct3DInterop::Draw(ID3D11Device1 * device=0x005c7744, ID3D11DeviceContext1 * context=0x005c8820, ID3D11RenderTargetView * renderTargetView=0x03112a38) Line 159   C++
    EmpiresAtWarComponent.dll!Direct3DContentProvider::Draw(ID3D11Device1 * device=0x005c7744, ID3D11DeviceContext1 * context=0x005c8820, ID3D11RenderTargetView * renderTargetView=0x03112a38) Line 64 C++
c++
windows-phone-8
cocos2d-x
cocos2d-x-3.0
tmx
asked on Stack Overflow Jan 30, 2015 by Vasu Mahesh • edited Jan 30, 2015 by Vasu Mahesh

1 Answer

0

The Answer was simple...

When you Import your resources you have to set

"Copy if newer" as Value to your Resource Under the Section "Copy to Output Directory" ... Doing that the file gets copied to your build otherwise it never reaches cocos. Hence the "Access Violation" ...

http://www.cocos2d-x.org/news/78

this link is very old as per VS 2014 . It says

The solution is very simple, that is to set the resource file Content field >to “ Yes” , the Item type field to “Does not participate in build”.

which wasn't the case for me. Hope it helps any other Cocos starter with the issue ! :)

answered on Stack Overflow Jan 31, 2015 by Vasu Mahesh • edited Jan 31, 2015 by Vasu Mahesh

User contributions licensed under CC BY-SA 3.0